This is the REST API providing functionality to operate products and their categories.
The third-party API being used previously has closed. So I wrote my own also for educational purposes.
- Download source code;
- Run
npm ito instal all dependencies; - Configure database connection in
./db.jsconfig file; - Run
npm run devcommand to start server. Default port is8080;
GET /products
fetch(`http://localhost:8080/products`)| Name | Description |
|---|---|
| searchQuery | Used to filter products by substring in its title. Case insensitive |
| categoryId | Used to filter products by it's categoryId |
[
{
"id": ...,
"title": "...",
"price": "...",
"description": "...",
"image": "...",
"categoryId": ...,
},
...
]GET /products/${id}
fetch(`http://localhost:8080/products/${id}`){
"id": ...,
"title": "...",
"price": "...",
"description": "...",
"image": "...",
"categoryId": ...,
}POST /products
fetch(`http://localhost:8080/products`, {
method: "POST",
body: {
title: "...",
price: "...",
description: "...",
image: "...",
categoryId: ...,
},
}){
"id": ...,
"title": "...",
"price": "...",
"description": "...",
"image": "...",
"categoryId": ...,
}PUT /products
fetch(`http://localhost:8080/products`, {
method: "PUT",
body: {
id: ...,
title: "...",
price: "...",
description: "...",
image: "...",
categoryId: ...
},
}){
"id": ...,
"title": "...",
"price": "...",
"description": "...",
"image": "...",
"categoryId": ...,
}DELETE /products
fetch(`http://localhost:8080/products/${id}`, {
method: "DELETE",
});{
"id": ...,
"title": "...",
"price": "...",
"description": "...",
"image": "...",
"categoryId": ...,
}GET /categories
fetch(`http://localhost:8080/categories`)[
{
"categoryId": ...,
"name": "...",
},
...
]{
id: Number,
title: String,
price: String,
description: String,
image: String,
categoryId: Number,
}{
categoryId: Number,
name: String,
}- NodeJS
- Express
- PostgreSQL