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

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


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

backend composer dotenv php restful-api

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# PHP simplest API Template

## Prerequisite

- php version: `8+`
- composer installed

## Quick start

copy .env.example to .env

```shell
cp .env.example .env
```

install packages

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

## api response demo

```json
{
"code": 200,
"data": [
{
"id": 1,
"name": "John"
},
{
"id": 2,
"name": "Allen"
}
],
"message": "",
"execution_time": "10.347ms"
}
```

## route register

```php
# ./src/index.php
# callback function
use demo\decorators\Param;
$app->router->get('/path/{id}', fn(#[Param('id')] string $id) => ['id' => $id]);

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