/rest-products-api

REST api implementation created in express. Product resource routes are protected by a JWT authorization requirement.

Primary LanguageTypeScript

REST Products API /w JWT Auth

REST api implementation created in express. Product resource routes are protected by a JWT authorization requirement. The JWT is implemented with a "refresh token" to allow the user to get a new access token without forcing a login every time the access token expires.

Appendix

File postman_collection.json includes whole required configuration to test app manually with Postman.

Tech stack:

Applicaiton framework

express: 4.18.2

Typing:

typescript: 4.9.4

Password hashing

bcrypt: 5.1.0

Authorization

jsonwebtoken: 8.5.1

Database and validation

mongoose: 6.8.0 zod: 3.19.1

Logging

pino: 8.7.0 pino-http: 8.2.1

Configuration

config: 3.3.8 dotenv: 16.0.3

Deployment

flyctl

API Reference

Users

Create a user / register

  POST /api/users
Request body Type Description
username string Required. User's username
password string Required. User's password
passwordConfirmation string Required. User's password again
email string Required. User's email

Get all users

  GET /api/users

Sessions

Create a session / sing in

  POST /api/sessions
Request body Type Description
username string Required. User's username
password string Required. User's password

Get all valid (signed in) sessions of current user

  GET /api/sessions

Invalidate current session, logout

  DELETE /api/sessions

Products

Get all products

  GET /api/products

Get specific product

  GET /api/products/${id}
Parameter Type Description
id string Required. Product's identifier

Create a product

  POST /api/products
Request body Type Description
name string Required. Product's name
quantity number Required. Product's quantity
price number Required. Price of 1 product
decription string Required. Minimum length: 120chars Product description
image string Required. URI to image of product

Update a product

  POST /api/products/${id}
Parameter Type Description
id string Required. Product's identifier
Request body Type Description
any product field from create product request any Optional.

Remove specific product

  DELETE /api/products/${id}
Parameter Type Description
id string Required. Product's identifier

Installation

Clone repository with git and then install it with yarn or npm:

  git clone https://github.com/kchn9/rest-users-products-api
  cd rest-users-products-api
  yarn install

License

MIT

Authors