https://github.com/aalfiann/slim-jwt-skeleton
This is a skeleton to built rest api with slim framework 3 and JWT Auth.
https://github.com/aalfiann/slim-jwt-skeleton
jwt-authentication rest-api skeleton slimframework
Last synced: 5 months ago
JSON representation
This is a skeleton to built rest api with slim framework 3 and JWT Auth.
- Host: GitHub
- URL: https://github.com/aalfiann/slim-jwt-skeleton
- Owner: aalfiann
- License: mit
- Created: 2019-05-14T19:31:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-11T23:00:08.000Z (over 6 years ago)
- Last Synced: 2025-06-22T20:08:11.392Z (8 months ago)
- Topics: jwt-authentication, rest-api, skeleton, slimframework
- Language: PHP
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Slim-JWT-Skeleton
[](https://packagist.org/packages/aalfiann/slim-jwt-skeleton)
[](https://packagist.org/packages/aalfiann/slim-jwt-skeleton)
[](https://github.com/aalfiann/slim-jwt-skeleton/blob/HEAD/LICENSE.md)
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](https://getcomposer.org/).
```
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.
```php
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](http://slimframework.com).
- This is a forked version from the original [slimphp/Slim-Skeleton](https://github.com/slimphp/Slim-Skeleton).