aalfiann / slim-api-skeleton
This is a skeleton to built rest api with slim framework 3.
Installs: 87
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:framework
Requires
- php: >=5.5
- aalfiann/slim-etag-middleware: ^1.0
- monolog/monolog: ^1.22
- slim/http-cache: ^0.4.0
- slim/slim: ^3.1
This package is auto-updated.
Last update: 2024-10-14 10:23:00 UTC
README
This is a skeleton to built rest api with slim framework 3.
Dependencies
- Logger >> monolog/monolog
- HTTP Cache >> slim/http-cache
- ETag Middleware >> aalfiann/slim-etag-middleware
Installation
Install this package via Composer.
composer create-project aalfiann/slim-api-skeleton [my-app-name]
Getting Started
How to create new application
- Go to modules directory
- Create new folder
my-app
- To create routes, you should follow this pattern >>
*.router.php
- Done
Example
This is the my-app.router.php
file
use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; // Route for /my-app $app->group('/my-app', function($app) { // Show index page // Try to open browser to http://yourdomain.com/my-app/ $app->get('/', function (Request $request, Response $response) { $data = [ 'welcome' => 'Hello World, this is my-app index page.', 'message' => 'This is my first app rest api with slim-api-skeleton.' ]; return $response->withJson($data,200,JSON_PRETTY_PRINT); })->setName("/"); });
Note:
- Documentation about
Slim
is available on slimframework.com. - This is a forked version from the original slimphp/Slim-Skeleton.