aalfiann / slim-jwt-skeleton
This is a skeleton to built rest api with slim framework 3 and JWT Auth.
Installs: 42
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:framework
Requires
- php: >=7.1
- aalfiann/slim-etag-middleware: ^1.0
- monolog/monolog: ^1.22
- slim/http-cache: ^0.4.0
- slim/slim: ^3.1
- tuupola/cors-middleware: ^0.9.4
- tuupola/slim-jwt-auth: ^3.3
This package is auto-updated.
Last update: 2024-10-12 10:41:04 UTC
README
This is a skeleton to built rest api with slim framework 3 and JWT Auth.
Dependencies
- Logger >> monolog/monolog
- HTTP Cache >> slim/http-cache
- Slim JWT Auth >> tuupola/slim-jwt-auth
- Cors Middleware >> tuupola/cors-middleware
- ETag Middleware >> aalfiann/slim-etag-middleware
Installation
Install this package via Composer.
composer create-project aalfiann/slim-jwt-skeleton [my-app-name]
Getting Started
How to generate Token
Send request to https://yourdomain.com/api/generate
Method:
GET / POST
Header:
Content-Type: application/json
Body:
{
"userid":"",
"scope":["get","post","delete","put"]
}
Output Response:
{
"token":"This is jwt token",
"expire" 1557908861
}
How to test
Send request to https://yourdomain.com/api/
Method:
GET / POST
Header:
Content-Type: application/json
X-Token: thisisyourjwttoken generated
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 just the part code of my_app.router.php
file,
please take look at modules/my_app/my_app.router.php
for more detail.
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-jwt-skeleton.' ]; return $response->withJson($data,200,JSON_PRETTY_PRINT); })->setName("/my_app/"); });
Note:
- Documentation about
Slim
is available on slimframework.com. - This is a forked version from the original slimphp/Slim-Skeleton.