This API has a simplified authentication flow for a basic ecommerce-store. It allows users to sign-up, login, add products, and see an itinerary of all their products.
- Choose your directory of choice and make sure to
cd
into it - Clone the repository running
git clone <SSH || HTTPS>
in the cli - Now, navigate into the directory and run
npm ci
to install the dependencies with a clean install - Run
npm run build
in order to compile TS to JS - Run
npm run start:nodemon
to start a server locally http://localhost:3000/, you will notice that this command will also CREATE both tables in SQLite for future insertions. Both tables are currently empty. - Great! You're up and running!
All endpoints were tested using Postman - I was hoping to convert these into tests but ended up running out of time. I have created a collection of endpoints in Postman for your ease of use! CLICK the following button to download the collection.
The following JSON is sent to the API from the client.
{
"email": "scott.jackson@gmail.com",
"name": "Scott Jackson",
"password": "Scott123"
}
Feel free to add more users.
Result --> 200, New user is added to the Advisor table. Check --> Send GET in Postman to http://localhost:3000/readAdvisorTable
The following JSON is sent to the API from the client.
{
"email": "scott.jackson@gmail.com",
"name": "Scott Jackson",
"password": "Scott123"
}
Result --> 200, JWT token is sent back to the client
The following JSON is sent to the API from the client.
{
"email": "scott.jackson@gmail.com",
"name": "Scott Jackson",
"password": "WrongPassword"
}
Result --> 401, Unauthenticated error
The following JSON is sent to the API from the client.
{
"name": "ruler",
"description": "stationary for office",
"price": "7.00"
}
IMPORTANT
Make sure to add the token to the Authorization header in Postman. Key = Authorization, value = Bearer + <token>
Result --> 200, New product is added to the Product table with the advisor_id as a foreign key Check --> Send GET in Postman to http://localhost:3000/readProductTable
The following JSON is sent to the API from the client.
{
"name": "ruler",
"description": "stationary for office",
"price": "7.00"
}
Result --> 401, Unauthenticated error with WWW-Authenticate in header
For this GET request, make sure to add the token of the user to the Authorization header. Depending on the token you add, the list of products associated with the token's id will be returned.
I hope you enjoy playing around with my API! 😎