Skip to content
1Alisa1Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Store-api

This is the REST API providing functionality to operate products and their categories.

Why?

The third-party API being used previously has closed. So I wrote my own also for educational purposes.

How to use?

  • Download source code;
  • Run npm i to instal all dependencies;
  • Configure database connection in ./db.js config file;
  • Run npm run dev command to start server. Default port is 8080;

Available routes

Get all products

Request

GET /products

fetch(`http://localhost:8080/products`)

Query parametrs (can be used multiple)

Name Description
searchQuery Used to filter products by substring in its title. Case insensitive
categoryId Used to filter products by it's categoryId

Response

[
  {
    "id": ...,
    "title": "...",
    "price": "...",
    "description": "...",
    "image": "...",
    "categoryId": ...,
  },
  ...
]

Get product by id

Request

GET /products/${id}

fetch(`http://localhost:8080/products/${id}`)

Response

{
  "id": ...,
  "title": "...",
  "price": "...",
  "description": "...",
  "image": "...",
  "categoryId": ...,
}

Add product

Request

POST /products

fetch(`http://localhost:8080/products`, {
  method: "POST",
  body: {
    title: "...",
    price: "...",
    description: "...",
    image: "...",
    categoryId: ...,
  },
})

Response

{
  "id": ...,
  "title": "...",
  "price": "...",
  "description": "...",
  "image": "...",
  "categoryId": ...,
}

Updating a product

Request

PUT /products

fetch(`http://localhost:8080/products`, {
  method: "PUT",
  body: {
    id: ...,
    title: "...",
    price: "...",
    description: "...",
    image: "...",
    categoryId: ...
  },
})

Response

{
  "id": ...,
  "title": "...",
  "price": "...",
  "description": "...",
  "image": "...",
  "categoryId": ...,
}

Delete product

Request

DELETE /products

fetch(`http://localhost:8080/products/${id}`, {
  method: "DELETE",
});

Response

{
  "id": ...,
  "title": "...",
  "price": "...",
  "description": "...",
  "image": "...",
  "categoryId": ...,
}

Get categories

Request

GET /categories

fetch(`http://localhost:8080/categories`)

Response

[
  {
    "categoryId": ...,
    "name": "...",
  },
  ...
]

Models

Product

{
  id: Number,
  title: String,
  price: String,
  description: String,
  image: String,
  categoryId: Number,
}

Category

{
  categoryId: Number,
  name: String,
}

Technologies

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages