A neat little framework for creating PHP APIs

Maintainers

👁 matthiasmullie

Package info

github.com/matthiasmullie/php-api

pkg:composer/matthiasmullie/php-api

Statistics

Installs: 420

Dependents: 1

Suggesters: 0

Stars: 4

Open Issues: 0

1.0.0 2017-12-08 21:36 UTC

Requires

Requires (Dev)

Suggests

Provides

None

Conflicts

None

Replaces

None

MIT c7233f2b6550da9ce4c2f68b06a4836344db6292

frameworkphpapiSkeleton

This package is auto-updated.

Last update: 2026-06-26 02:27:34 UTC


README

👁 Build status
👁 Code coverage
👁 Code quality
👁 Latest version
👁 Downloads total
👁 License

Example usage

Setting up is really simple.

You'll need a routing config:

test:
 method: [GET, POST]
 path: /
 handler: MatthiasMullie\ApiExample\ExampleController

A few lines to bootstrap, in a file where all of your requests end up:

$routes = new MatthiasMullie\Api\Routes\Providers\YamlRouteProvider(__DIR__.'/../config/routes.yml');
$handler = new MatthiasMullie\Api\RequestHandler($routes);
$response = $handler->route(GuzzleHttp\Psr7\ServerRequest::fromGlobals());
$handler->output($response);

And a controller:

namespace MatthiasMullie\ApiExample;

class ExampleController implements MatthiasMullie\Api\Controllers\JsonController
{
 public function __invoke(Psr\Http\Message\ServerRequestInterface $request, ResponseInterface $response, array $args)
 {
 // hey there, I can process your request!

 return [
 'status_code' => 200,
 'hello' => 'world',
 ];
 }
}

Or take a look at this exact same example in a clean repo, at matthiasmullie/php-api-example.

Installation

Simply add a dependency on matthiasmullie/php-api to your composer.json file if you use Composer to manage the dependencies of your project:

composer require matthiasmullie/php-api

Although it's recommended to use Composer, you can actually include these files anyway you want.

License

php-api is MIT licensed.