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
- Host: GitHub
- URL: https://github.com/gxiang314/php-api
- Owner: GXiang314
- License: mit
- Created: 2024-03-12T20:18:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-08T12:37:20.000Z (3 months ago)
- Last Synced: 2025-04-08T13:39:51.499Z (3 months ago)
- Topics: backend, composer, dotenv, php, restful-api
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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'])
```