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.
File postman_collection.json includes whole required configuration to test app manually with Postman.
express: 4.18.2
typescript: 4.9.4
bcrypt: 5.1.0
jsonwebtoken: 8.5.1
mongoose: 6.8.0 zod: 3.19.1
pino: 8.7.0 pino-http: 8.2.1
config: 3.3.8 dotenv: 16.0.3
flyctl
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 /api/users POST /api/sessions| Request body | Type | Description |
|---|---|---|
username |
string |
Required. User's username |
password |
string |
Required. User's password |
GET /api/sessions DELETE /api/sessions GET /api/products GET /api/products/${id}| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Product's identifier |
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 |
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. |
DELETE /api/products/${id}| Parameter | Type | Description |
|---|---|---|
id |
string |
Required. Product's identifier |
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