Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/gxiang314/php-api


https://github.com/gxiang314/php-api

Last synced: about 6 hours ago
JSON representation

Awesome Lists containing this project

README

        

# PHP simplest API Template

##### quick start:

```shell
composer install
composer start # run php server http://localhost:8000
```

##### api response demo:
http://localhost:8000/api/demo
```json
{
"code": 200,
"data": [
{
"id": 1,
"name": "John"
},
{
"id": 2,
"name": "Allen"
}
],
"message": "ok.",
"execution_time": 0.0009458065032958984
}
```

##### route register:

```php
# ./src/public/index.php
# callback function
$app->router->get('path/{var}', function() {
return json_encode(['data' => '1234'])
})

# class method
$app->router->post('path', [DemoController::class, 'methodName'])
```