How to give access to your data
Table of Contents
- 🎯 Objective
- 🏗 Prerequisites
⤵️ List of endpoints to implement- 👩💻 Just tell me what to do
- 📦 Suggested node modules
- 🛣️ Related Theme and courses
Build an api with Express to request data from your database...
- Be sure to have a clean working copy.
This means that you should not have any uncommitted local changes.
❯ cd /path/to/workspace/clear-fashion
❯ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
- Pull the
master
branch to update your local with the new remote changes
❯ git remote add upstream git@github.com:92bondstreet/clear-fashion.git
## or ❯ git remote add upstream https://github.com/92bondstreet/clear-fashion
❯ git fetch upstream
❯ git pull upstream master
- Check the terminal output for the command
node sandbox-db.js
❯ cd /path/to/workspace/clear-fashion/server
## install new dependencies
❯ yarn
## or ❯ npm install
❯ node sandbox-db.js
- Check the terminal output for the command
node api.js
❯ cd /path/to/workspace/clear-fashion/server
## install new dependencies
❯ yarn
## or ❯ npm install
❯ node api.js
Fetch a specific product.
❯ curl -H "Accept: application/json" http://localhost:8092/products/f9360699-2c7d-5cec-8529-374d3e166f87
{
"_id": "f9360699-2c7d-5cec-8529-374d3e166f87",
"link": "https://www.loom.fr/collections/hauts/products/le-t-shirt",
"brand": "loom",
"price": 20,
"name": "Le t-shirt en coton",
"photo":"//cdn.shopify.com/s/files/1/1355/7899/products/loom_tshirt_coton_gris_anthracite_face_2_394x.jpg?v=1611741180"
}
Search for specific products
This endpoint accepts the following optional query string parameters:
limit
- number of products to return (default: 12)brand
- filter by brand (default: All brands)price
- filter by price (default: All price)
The results array should be sorted by price in ascending way.
❯ curl -H "Accept: application/json" http://localhost:8092/products/search?limit=5&brand=loom&price=30
{
"limit": 5,
"total": 2,
"results": [
{
"_id": "f9360699-2c7d-5cec-8529-374d3e166f87",
"link": "https://www.loom.fr/collections/hauts/products/le-t-shirt",
"brand": "loom",
"price": 20,
"name": "Le t-shirt en coton",
"photo":"//cdn.shopify.com/s/files/1/1355/7899/products/loom_tshirt_coton_gris_anthracite_face_2_394x.jpg?v=1611741180"
},
{
"_id": "8ad2f7ed-652f-57a9-b48e-659b8e4fa3d2",
"link": "https://www.loom.fr/collections/hauts/products/le-t-shirt-en-coton-bio",
"brand": "loom",
"price": 25},
"name": "Le t-shirt en coton bio",
"photo": "//cdn.shopify.com/s/files/1/1355/7899/products/tshirtloomcotonbioblancface2_394x.jpg?v=1611740926"
}
]
}
-
Implement the endpoints
-
Commit your modification
❯ cd /path/to/workspace/clear-fashion
❯ git add -A && git commit -m "feat(get-product): get a specific product"
(why following a commit message convention?)
- Commit early, commit often
- Don't forget to push before the end of the workshop
❯ git push origin master
Note: if you catch an error about authentication, add your ssh to your github profile.
If you need some helps on git commands, read git - the simple guide