An open API service indexing awesome lists of open source software.

https://github.com/luizeof/php-rest-api

Easy way to create a PHP Rest API with Basic Authentication
https://github.com/luizeof/php-rest-api

api auth http php rest

Last synced: about 1 month ago
JSON representation

Easy way to create a PHP Rest API with Basic Authentication

Awesome Lists containing this project

README

          

# php-rest-api

Easy way to create a PHP REST API with ```Basic Authentication```

## Installing

To install `luizeof/php-rest-api`, run this command on your terminal:

```bash
composer require luizeof/php-rest-api
```

## Importing

Import `autoload` on your project:

```php
require __DIR__ . '/vendor/autoload.php';
```

## Sample Usage

```php
validate_auth( function() use ($api) {

if ($api->get_username() == "luiz") {
return true;
} else {
return false;
}

}); // validate_auth()

$arr = array('id' => 1, 'title' => "Exemplo", 'date' => "01/01/2020", 'tags'=> array("php","docker","flutter"), 'author' => "luizeof");

$api->array_to_json($arr);

$api->request_success();

} catch (Throwable $t) {

$api->request_error($t);

} catch (Exception $e) {

$api->request_error($e);

} finally {

unset($api);

}

?>
```