A simple REST API for creating awesome online shops.
- Install packages from npm:
npm install- Create
.envfile with data to connect to the PostgreSQL:
TYPEORM_USERNAME = postgres;
TYPEORM_PASSWORD = root;
TYPEORM_HOST = localhost;
TYPEORM_PORT = 5432;
TYPEORM_DATABASE = shop - api;
JWT_SECRET = SomeSecretKey;- Create production build & run server:
npm run buildnpm startOr launch server in develepment mode with nodemon:
npm run devBase server url: http://localhost:5000
You can use a specially prepared collection of endpoints for Insomnia client.
For this just import
./shop-api.insomnia.jsonfile.
Auth for users.
| Method | End-Point | Description |
|---|---|---|
POST |
/api/register |
Create a new user |
POST |
/api/login |
Login to user account |
GET |
/api/verify |
Verify JWT token and create a new one |
By default all new accounts has a
clientrole. To get administrator rights, you need to change the role field toadminin the database.
Categories for products.
| Method | End-Point | Description |
|---|---|---|
POST |
/api/category |
Create a new category (*For admins) |
GET |
/api/category |
List of all categories |
CRUD opeations with products.
| Method | End-Point | Description |
|---|---|---|
POST |
/api/product |
Create a new product (*For admins) |
GET |
/api/products |
List of all products |
GET |
/api/products/:category |
List of all products by category |
GET |
/api/product/:id |
Get a product by id |
PUT |
/api/product |
Update a product (*For admins) |
DELETE |
/api/product/:id |
Delete a product by id (*For admins) |
For
/productsendpoints you can use?page={int}&limit={int}query params
Operations with the shopping cart.
| Method | End-Point | Description |
|---|---|---|
GET |
/api/cart/add/:productId?amount=1 |
Add a product to user cart (*For authorized) |
GET |
/api/cart |
Get user cart (*For authorized) |
For running tests just use this command:
npm testTo pass all tests successfully, make sure that you change the credentials for the administrator account in the *spec.ts files. Or you can create an administrator account (and change role to admin in your database for this) that have already been used in this tests:
email: "admin@test.com",
password: "admin",