Interacting with this api, you are able to create and authenticate clients using Json Web Tokens which are needed to perform CRUD Operations on Transactions.
The API is live at https://jwtapi.ayomideakinbo.live/
This API has also been documented using Postman, find this documentation here at : https://documenter.getpostman.com/view/11792638/2s93eYUBzR
Please feel free to visit my Notion blog page where I elaborate on the project and share my thought process that informed its development. https://www.notion.so/JWT-Authentication-Api-a6bbb501f0784ce8a7b2461210ddd93d?pvs=4
To get started, clone this repository to your local machine and run npm install
to install the required dependencies. You will also need to create a .env
file in the root directory of the project following the format in the env_example file located in the root of this repository. You can then start the server by running npm start
.
To access certain resources and perform certain operations, a client needs to be authenticated by being registering and logging in. Resources that require authentication will be tagged with 'Authentication-Needed' and will require you to send a request Authorization
header with value of Bearer access_token
POST /api/v1/register
The request body needs to be in JSON format and must include the following properties
firstName
- String - RequiredlastName
- String - Requiredemail
- String - Requiredpassword
- String - RequiredrepeatPassword
- String -Required - Reference to password
Example Request
POST /api/v1/register
{
"firstName": "Tobi",
"lastName": "John",
"email": "tobyjohn@gmail.com"
"password": "randompasswordbelongingtotobyjohn",
"repeatPassword": "randompasswordbelongingtotobyjohn"
}
Example, Successful Response
{
"success": "true",
"message": "User Created",
"status": "201"
"data" : {
"firstName": "tobi",
"lastName": "john",
"email": "tobyjohn@gmail.com"
}
}
Example, Failed Response
{
"success": false,
"message": "An error has occurred",
"status": 409,
"error": [
{
"message": "User Already Exists"
}
]
}
POST /api/v1/login
The request body needs to be in JSON format and must include the following properties
email
- String - Requiredpassword
- String - Required
Example Request
POST /api/v1/login
{
"email": "tobyjohn@gmail.com"
"password": "randompasswordbelongingtotobyjohn"
}
Example Success Response
{
"email": "tobyjohn@gmail.com"
"access_token": "${jwt_token_provided}"
}
${jwt_token_provided}
will be the actual jwt provided by in the response. This jwt will last for 1 day from the time of logging in.
GET /api
Returns status of api.
POST /api/v1/transactions
Creates a transaction. 'Authentication-Needed'
The request body needs to be in JSON format and must include the following properties
depositorName
- String - RequiredtransactionAmount
- Number - Required
Example Request
POST /api/v1/transactions
Authorization: Bearer <access_token>
{
"depositorName": "Thomas Shelby"
"transactionAmount": 2000
}
Example, Successful Response
{
"success": "true",
"message": "Transaction Created",
"status:" 201
}
Example, Failed Response
{
"success": "false",
"message": "An error has occurred",
"status": 401,
"error": [
{
"message": "Unauthorized"
}
]
}
POST /api/v1/transactions
Returns all transactions. 'Authentication-Needed'
POST /api/v1/transactions/
Returns all query transactions. 'Authentication-Needed'
The request query parameters are not required but can be added if a client wants to query the transactions to be returned, they are:
min-amount
- Number. If provided alone returns all transactions with transaction amounts greater than or equal to provided valuemax-amount
- Number. If provided alone returns all transactions with transaction amounts less than or equal to provided value
If both min-amount
and max-amount
query parameters are provided, the api returns all transactions with transaction amounts between both.
name
- String. If provided returns transactions by name of depositor.
POST /api/v1/transactions/:id
Returns a transaction. 'Authentication-Needed'
PATCH /api/v1/transactions/:id
Updates a transaction. 'Authentication-Needed'
The request body needs to be in JSON format and must include the following properties
depositorName
- String - RequiredtransactionAmount
- Number - Required
Example Request
PATCH /api/v1/transactions/:id
Authorization: Bearer <access_token>
{
"depositorName": "charles winkage",
"transactionAmount": 1500
}
DELETE /api/v1/transactions/:id
Deletes a transaction. 'Authentication-Needed'
Before proceeding with this documentation, I want to bring to your attention that I have purposely not created a route that enables a client to log out of the system. Please once again visit my Notion blog page where I talk about why and my intentions moving forward.