This is a simple REST API to manage a petshop coded in javascript (uses NodeJS and Express + MySQL) for studying purposes.
node ./api/index.js
The REST API is described below. Some examples were added to the database.
GET api/suppliers/
curl -i -H "Accept:application/json" -H "http://localhost:3000/api/suppliers/"
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 234
ETag: W/"ea-MM3mwY1usnrlaS3yROn10v96aUI"
Date: Tue, 30 Mar 2021 15:46:41 GMT
Connection: keep-alive
Keep-Alive: timeout=5
[{"id":1,"category":"food","company":"JS food for cats"},{"id":4,"category":"toys","company":"JS toys for cats"},{"id":5,"category":"toys","company":"JS toys for dogs"},{"id":6,"category":"toys","company":"Maximillian FOOD for Cats"}]
POST api/suppliers/
curl -i --location --request POST "http://localhost:3000/api/suppliers" --header "Content-Type:application/json" --header "Accept:application/json" --data-raw "{\"company\":\"Maximum Toys LTDA\",\"category\":\"toys\",\"email\":\"contato@maximum.com\"}"
HTTP/1.1 201 Created
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 56
ETag: W/"38-wcQm4JEEhqK7YKHmOvs+6TOwAeQ"
Date: Tue, 30 Mar 2021 16:26:32 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":8,"category":"toys","company":"Maximum Toys LTDA"}
GET /suppliers/id
curl -i --location --request GET "http://localhost:3000/api/suppliers/1" --header "Content-Type:application/json" --header "Accept:application/json"
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 174
ETag: W/"ae-d77IPbRqXGfnT0HjzNv09KotuX0"
Date: Tue, 30 Mar 2021 16:30:15 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":"1","category":"food","email":"sales@js.petshop","company":"JS food for cats","createdAt":"2021-03-17T23:43:45.000Z","updatedAt":"2021-03-17T23:43:45.000Z","version":0}
GET /suppliers/id
curl -i -H 'Accept: application/json' http://localhost:7000/thing/9999
curl -i --location --request GET "http://localhost:3000/api/suppliers/9999" --header "Content-Type:application/json" --header "Accept:application/json"
HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 48
ETag: W/"30-lPobSTL/VdLin7S8GwDLt881ZaA"
Date: Tue, 30 Mar 2021 16:32:28 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":0,"message":"[ERROR] Supplier not found!"}
PUT /suppliers/:id
curl -i --location --request PUT "http://localhost:3000/api/suppliers/1" --header "Content-Type:application/json" --header "Accept:application/json" --data-raw "{\"company\":\"JS food for cats and dogs\"}"
HTTP/1.1 204 No Content
X-Powered-By: Express
Content-Type: application/json
Access-Control-Allow-Origin: *
Date: Tue, 30 Mar 2021 16:41:51 GMT
Connection: keep-alive
Keep-Alive: timeout=5
PUT /suppliers/:id
curl -i --location --request PUT "http://localhost:3000/api/suppliers/1" --header "Content-Type:application/json" --header "Accept:application/json" --data-raw "{\"description\":\"Food for cats\"}"
HTTP/1.1 400 Bad Request
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 46
ETag: W/"2e-Sf6IBlWHyK+8wXSZq2a86sFpjdY"
Date: Tue, 30 Mar 2021 16:44:26 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":2,"message":"[ERROR] Data not provided"}
DELETE /suppliers/id
curl -i --location --request DELETE "http://localhost:3000/api/suppliers/8" --header "Content-Type:application/json"
HTTP/1.1 204 No Content
X-Powered-By: Express
Content-Type: application/json
Access-Control-Allow-Origin: *
Date: Tue, 30 Mar 2021 16:46:37 GMT
Connection: keep-alive
Keep-Alive: timeout=5
DELETE /suppliers/id
curl -i --location --request DELETE "http://localhost:3000/api/suppliers/8" --header "Content-Type:application/json"
HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 48
ETag: W/"30-lPobSTL/VdLin7S8GwDLt881ZaA"
Date: Tue, 30 Mar 2021 16:47:03 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":0,"message":"[ERROR] Supplier not found!"}
GET /suppliers/id/products
curl -i --location --request GET "http://localhost:3000/api/suppliers/1/products" --header "Content-Type:application/json"
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 2
ETag: W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"
Date: Tue, 30 Mar 2021 16:52:35 GMT
Connection: keep-alive
Keep-Alive: timeout=5
[]
POST api/suppliers/id/products
curl -i --location --request POST "http://localhost:3000/api/suppliers/1/products" --header "Content-Type:application/json" --data-raw "{\"title\":\"snackos for cattos\",\"price\":20,\"inventory\":50}"
HTTP/1.1 201 Created
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
ETag: 0
Last-Modified: 1617123579365
Location: /api/suppliers/1/products/7
Content-Length: 37
Date: Tue, 30 Mar 2021 16:59:39 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":7,"title":"snackos for cattos"}
DELETE api/suppliers/id/products/id
curl -i --location --request DELETE "http://localhost:3000/api/suppliers/6/products/6" --header "Content-Type:application/json"
HTTP/1.1 204 No Content
X-Powered-By: Express
Content-Type: application/json
Access-Control-Allow-Origin: *
Date: Tue, 30 Mar 2021 17:05:38 GMT
Connection: keep-alive
Keep-Alive: timeout=5
DELETE api/suppliers/id/products/id
curl -i --location --request PUT "http://localhost:3000/api/suppliers/1/products/7" --header "Content-Type:application/json" --data-raw "{\"title\":\"snackos for doggos\"}"
HTTP/1.1 204 No Content
X-Powered-By: Express
Content-Type: application/json
Access-Control-Allow-Origin: *
ETag: 0
Last-Modified: 1617124248000
Date: Tue, 30 Mar 2021 17:10:48 GMT
Connection: keep-alive
Keep-Alive: timeout=5
GET api/suppliers/id/products/id
curl -i --location --request GET "http://localhost:3000/api/suppliers/1/products/999" --header "Content-Type:application/json"
HTTP/1.1 404 Not Found
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Content-Length: 47
ETag: W/"2f-YkHRn5j8V3Cpa/29q1O/YjgBdxE"
Date: Tue, 30 Mar 2021 17:11:55 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":0,"message":"[ERROR] Product not found!"}
GET api/suppliers/id/products/id
curl -i --location --request GET "http://localhost:3000/api/suppliers/1/products/7" --header "Content-Type:application/json"
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
ETag: 0
Last-Modified: 1617124248000
Content-Length: 173
Date: Tue, 30 Mar 2021 17:16:10 GMT
Connection: keep-alive
Keep-Alive: timeout=5
{"id":"7","title":"snackos for doggos","price":19.99,"inventory":50,"supplier":"1","createdAt":"2021-03-30T17:02:52.000Z","updatedAt":"2021-03-30T17:10:48.000Z","version":0}