Skip to content

GXiang314/php-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP simplest API Template

Prerequisite

  • php version: 8+
  • composer installed

Quick start

copy .env.example to .env

cp .env.example .env

install packages

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

api response demo

http://localhost:8000/api/demo

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

route register

# ./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'])

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages