A Store REST API built with Express JS, MySQL and Sequelize
Local Installation End Points Credits
This projects is configured using Yarn 2 - https://yarnpkg.com/getting-started
You may need to run yarn install
twice to start the project successfully.
You will need to edit the .env.EXAMPLE
to your local MySQL installation.
Setup the database from the db
folder. Start MySQLSH and run the schema.sql file.
Once setup you should be able to start the server using yarn start
.This will confirm if the database has correctly started.
If successful, you can open a new terminal and run yarn seed
to populate the server with data for testing.
End points for https://github.com/minusInfinite/estore-backend
The end points for a completing CRUD actions against the Store's Category API
Add a New Category to the database. It will provide an ID
Endpoint:
Method: POST
Type: RAW
URL: http://localhost:3001/api/categories/
Body:
{
"category_name": "mugs"
}
More example Requests/Responses:
Body:
{
"category_name": "mugs"
}
{
"id": 7,
"category_name": "mugs"
}
Status Code: 200
Delete a single categories in the database by the ID at the end of the URL.
Endpoint:
Method: DELETE
Type:
URL: http://localhost:3001/api/categories/9
More example Requests/Responses:
"Deleted 9"
Status Code: 200
Get all categories in the database and related products.
Endpoint:
Method: GET
Type:
URL: http://localhost:3001/api/categories/
More example Requests/Responses:
[
{
"id": 1,
"category_name": "Jumpers",
"products": [
{
"id": 1,
"product_name": "Plain T-Shirt",
"price": 14.99,
"stock": 14,
"category_id": 1
}
]
},
{
"id": 2,
"category_name": "Shorts",
"products": [
{
"id": 5,
"product_name": "Cargo Shorts",
"price": 29.99,
"stock": 22,
"category_id": 2
}
]
},
{
"id": 3,
"category_name": "Music",
"products": [
{
"id": 4,
"product_name": "Top 40 Music Compilation Vinyl Record",
"price": 12.99,
"stock": 50,
"category_id": 3
}
]
},
{
"id": 4,
"category_name": "Hats",
"products": [
{
"id": 7,
"product_name": "Basketball Cap",
"price": 25,
"stock": 10,
"category_id": 4
},
{
"id": 3,
"product_name": "Branded Baseball Hat",
"price": 22.99,
"stock": 12,
"category_id": 4
}
]
},
{
"id": 5,
"category_name": "Shoes",
"products": [
{
"id": 2,
"product_name": "Running Sneakers",
"price": 90,
"stock": 25,
"category_id": 5
}
]
}
]
Status Code: 200
Get a single categories in the database and related products by the ID at the end of the URL.
Endpoint:
Method: GET
Type:
URL: http://localhost:3001/api/categories/1
More example Requests/Responses:
{
"id": 1,
"category_name": "Jumpers",
"products": [
{
"id": 1,
"product_name": "Plain T-Shirt",
"price": 14.99,
"stock": 14,
"category_id": 1
}
]
}
Status Code: 200
Update a single categories in the database by the ID at the end of the URL.
Endpoint:
Method: PUT
Type: RAW
URL: http://localhost:3001/api/categories/7
Body:
{
"category_name": "Jumpers"
}
More example Requests/Responses:
Body:
{
"category_name": "Jumpers"
}
{
"message": "Jumpers Updated"
}
Status Code: 202
Add a New Product to the database, while options you can provide a category ID and Tag IDs in an Array.
Endpoint:
Method: POST
Type: RAW
URL: http://localhost:3001/api/products/
Body:
{
"product_name": "Basketball Cap",
"price": 25.0,
"stock": 10,
"category_id": 4,
"tagIds": [5]
}
More example Requests/Responses:
Body:
{
"product_name": "Basketball Cap",
"price": 25.0,
"stock": 10,
"category_id": 4,
"tagIds": [5]
}
[
{
"id": 15,
"productId": 8,
"tagId": 5
}
]
Status Code: 200
Delete a single Product in the database by the ID at the end of the URL.
Endpoint:
Method: DELETE
Type:
URL: http://localhost:3001/api/products/9
More example Requests/Responses:
"Deleted 9"
Status Code: 200
Get all Products in the database and related categories and tags
Endpoint:
Method: GET
Type:
URL: http://localhost:3001/api/products/
More example Requests/Responses:
[
{
"id": 1,
"product_name": "Plain T-Shirt",
"price": 14.99,
"stock": 14,
"category_id": 1,
"category": {
"id": 1,
"category_name": "Jumpers"
},
"tags": [
{
"id": 6,
"tag_name": "white",
"product_tag": {
"id": 1,
"product_id": 1,
"tag_id": 6,
"productId": 1,
"tagId": 6
}
},
{
"id": 7,
"tag_name": "gold",
"product_tag": {
"id": 2,
"product_id": 1,
"tag_id": 7,
"productId": 1,
"tagId": 7
}
},
{
"id": 8,
"tag_name": "pop culture",
"product_tag": {
"id": 3,
"product_id": 1,
"tag_id": 8,
"productId": 1,
"tagId": 8
}
}
]
},
{
"id": 2,
"product_name": "Running Sneakers",
"price": 90,
"stock": 25,
"category_id": 5,
"category": {
"id": 5,
"category_name": "Shoes"
},
"tags": [
{
"id": 6,
"tag_name": "white",
"product_tag": {
"id": 4,
"product_id": 2,
"tag_id": 6,
"productId": 2,
"tagId": 6
}
}
]
},
{
"id": 3,
"product_name": "Branded Baseball Hat",
"price": 22.99,
"stock": 12,
"category_id": 4,
"category": {
"id": 4,
"category_name": "Hats"
},
"tags": [
{
"id": 1,
"tag_name": "rock music",
"product_tag": {
"id": 5,
"product_id": 3,
"tag_id": 1,
"productId": 3,
"tagId": 1
}
},
{
"id": 3,
"tag_name": "blue",
"product_tag": {
"id": 6,
"product_id": 3,
"tag_id": 3,
"productId": 3,
"tagId": 3
}
},
{
"id": 4,
"tag_name": "red",
"product_tag": {
"id": 7,
"product_id": 3,
"tag_id": 4,
"productId": 3,
"tagId": 4
}
},
{
"id": 5,
"tag_name": "green",
"product_tag": {
"id": 8,
"product_id": 3,
"tag_id": 5,
"productId": 3,
"tagId": 5
}
}
]
}
]
Status Code: 200
Get a single Product in the database and related categories and tags, with the ID number at the end of the URL
Endpoint:
Method: GET
Type:
URL: http://localhost:3001/api/products/1
More example Requests/Responses:
{
"id": 1,
"product_name": "Plain T-Shirt",
"price": 14.99,
"stock": 14,
"category_id": 1,
"category": {
"id": 1,
"category_name": "Jumpers"
},
"tags": [
{
"id": 6,
"tag_name": "white",
"product_tag": {
"id": 1,
"product_id": 1,
"tag_id": 6,
"productId": 1,
"tagId": 6
}
},
{
"id": 7,
"tag_name": "gold",
"product_tag": {
"id": 2,
"product_id": 1,
"tag_id": 7,
"productId": 1,
"tagId": 7
}
},
{
"id": 8,
"tag_name": "pop culture",
"product_tag": {
"id": 3,
"product_id": 1,
"tag_id": 8,
"productId": 1,
"tagId": 8
}
}
]
}
Status Code: 200
Update the tags on a single Product in the database by the ID at the end of the URL.
Endpoint:
Method: PUT
Type: RAW
URL: http://localhost:3001/api/products/1
Body:
{
"tagIds": [5]
}
More example Requests/Responses:
Body:
{
"tagIds": [5]
}
[
3,
[
{
"id": 16,
"productId": "1",
"tagId": 5
}
]
]
Status Code: 200
Add a New Tag to the database. It will provide an ID
Endpoint:
Method: POST
Type: RAW
URL: http://localhost:3001/api/tags/
Body:
{
"tag_name": "rock music"
}
More example Requests/Responses:
Body:
{
"tag_name": "rock music"
}
{
"id": 9,
"tag_name": "rock music"
}
Status Code: 200
Delete the Tag in the database by the ID at the end of the URL.
Endpoint:
Method: DELETE
Type:
URL: http://localhost:3001/api/tags/2
More example Requests/Responses:
"Deleted 2"
Status Code: 200
Get all Tags in the database and related categories and products
Endpoint:
Method: GET
Type:
URL: http://localhost:3001/api/tags/
More example Requests/Responses:
[
{
"id": 1,
"tag_name": "rock music",
"products": [
{
"id": 3,
"product_name": "Branded Baseball Hat",
"price": 22.99,
"stock": 12,
"category_id": 4,
"product_tag": {
"id": 5,
"product_id": 3,
"tag_id": 1,
"productId": 3,
"tagId": 1
}
},
{
"id": 4,
"product_name": "Top 40 Music Compilation Vinyl Record",
"price": 12.99,
"stock": 50,
"category_id": 3,
"product_tag": {
"id": 9,
"product_id": 4,
"tag_id": 1,
"productId": 4,
"tagId": 1
}
}
]
},
{
"id": 2,
"tag_name": "pop music",
"products": [
{
"id": 4,
"product_name": "Top 40 Music Compilation Vinyl Record",
"price": 12.99,
"stock": 50,
"category_id": 3,
"product_tag": {
"id": 10,
"product_id": 4,
"tag_id": 2,
"productId": 4,
"tagId": 2
}
}
]
},
{
"id": 3,
"tag_name": "blue",
"products": [
{
"id": 3,
"product_name": "Branded Baseball Hat",
"price": 22.99,
"stock": 12,
"category_id": 4,
"product_tag": {
"id": 6,
"product_id": 3,
"tag_id": 3,
"productId": 3,
"tagId": 3
}
},
{
"id": 5,
"product_name": "Cargo Shorts",
"price": 29.99,
"stock": 22,
"category_id": 2,
"product_tag": {
"id": 12,
"product_id": 5,
"tag_id": 3,
"productId": 5,
"tagId": 3
}
}
]
}
]
Status Code: 200
Get a single Tag in the database and related categories and products, with the ID number at the end of the URL
Endpoint:
Method: GET
Type:
URL: http://localhost:3001/api/tags/1
More example Requests/Responses:
{
"id": 1,
"tag_name": "rock music",
"products": [
{
"id": 3,
"product_name": "Branded Baseball Hat",
"price": 22.99,
"stock": 12,
"category_id": 4,
"product_tag": {
"id": 5,
"product_id": 3,
"tag_id": 1,
"productId": 3,
"tagId": 1
}
},
{
"id": 4,
"product_name": "Top 40 Music Compilation Vinyl Record",
"price": 12.99,
"stock": 50,
"category_id": 3,
"product_tag": {
"id": 9,
"product_id": 4,
"tag_id": 1,
"productId": 4,
"tagId": 1
}
}
]
}
Status Code: 200
Update the Tag name in the database by the ID at the end of the URL.
Endpoint:
Method: PUT
Type: RAW
URL: http://localhost:3001/api/tags/1
Body:
{
"tag_name": "black"
}
More example Requests/Responses:
Body:
{
"tag_name": "black"
}
{
"message": "black Updated"
}
Status Code: 202
API Generated by docgen