This toolkit is for people who like to build web REST API's with token based structure like JWT using PHP. Its goal is to enable you to develop api much faster than you could if you were writing code from scratch, by providing a template for your workings with the REST API with JWT based tokens.
Release Information
This repo contains in-development code for future releases.
Features
- Complete REST API control
- JWT based access tokens
- CRUD operations
- Register/Login/Regenerate Token Mechanism
- Proper Authentication
- Validation control
- DB migration given
- Routing handled
- Postman collection added
Setup Instruction
- Rename
env
to.env
and tailor for your app. - Go to the directory where you have
composer.json
and run the following command:composer install
. - Change
JWT_SECRET_KEY
&JWT_TIME_TO_LIVE
according to your need. - Change
app.baseURL
in .env - Change DB credentials accordingly in .env
- Create a database with the same name in MySQL.
- Run command
php spark migrate
to create database tables from CI Migration. - Open postman and import
RESTAPI_JWT_CI.postman_collection.json
. - Register a User.
- Login with that user to get the
access_token
. - To perform crud operations you have to supply the
access_token
inAuthorization->Type->Bearer Token
for authorization with other data in body section. - If
access_token
expired, you can also regenerateaccess_token
by providingemail
.
Important
Initially access_token
has been set for 60 minute.
Warning
JWT_SECRET_KEY
must be changed for your own protection in production environment.
Tip
Either way, running install
when a composer.lock
file is present resolves and installs all dependencies that you listed in composer.json
, but Composer uses the exact versions listed in composer.lock
to ensure that the package versions are consistent for everyone working on your project.
Postman Calls & Methods
POST : http://localhost/api_jwt_ci4/public/register
Body |
---|
name |
password |
POST : http://localhost/api_jwt_ci4/public/login
Body |
---|
password |
GET : http://localhost/api_jwt_ci4/public/client
Headers | Body |
---|---|
Authorization |
POST : http://localhost/api_jwt_ci4/public/client
Headers | Body |
---|---|
Authorization | name |
retainer_fee |
PUT : http://localhost/api_jwt_ci4/public/client/:id
Headers | Body |
---|---|
Authorization | name |
retainer_fee |
DELETE : http://localhost/api_jwt_ci4/public/client/:id
Headers | Body |
---|---|
Authorization |
POST : http://localhost/api_jwt_ci4/public/reGenToken
Body |
---|
Server Requirements
PHP version 7.3 or higher is required, with the following extensions installed:
References