Detective, here are your tasks for the next two days:
On day 1 we'll fetch data from the server about the northcoders and store it locally.
On day 2 we'll leak this data to the world and create our own web server that will respond with the data we collected.
-
Use node's HTTP module to retrieve a list of all the available people at the following end point:
https://nc-leaks.herokuapp.com/api/people
. -
Once you have the list of people. Find all of the northcoders from the list and save their data to a file.
-
Now you have access to the northcoders' usernames, you can obtain more information for each person. Retrieve everyone's interests and store it in another file from
https://nc-leaks.herokuapp.com/api/people/:username/interests
. -
Do the same for everyone's pets from
https://nc-leaks.herokuapp.com/api/people/:username/pets
. -
Automation is great. Automate the above steps by putting them in a single npm command.
Think about how you are going to store the data, and what file format will be best. Make sure you read the relevant documentation (hint: node http docs.
Use a library such as superagent
to make your requests easier to handle. Refactor your pets in interests requests to use superagent instead of node's http module.
Today we will leak this information to the world! You will introduce yourself to web servers and RESTful APIs by building a server that serves all the data you collected yesterday.
-
Using Node's http module create a web server that responds with 'hello' when it receives a GET request on the path /api
-
Add a GET
/api/northcoders
endpoint that serves a JSON object of all the northcoders which shows their name, job details, image and username. -
Add a GET
/api/northcoders/:username
parametric endpoint which serves the above information for one northcoder. -
Add a GET
/api/pets/:username
parametric endpoint which serves a northcoders pets. -
Add a GET
/api/interests/:username
parametric endpoint which serves a northcoders interests. -
Add some error handling to your server. What should it respond with if you receive a request for a username that doesn't exist? What status code should you respond with?
-
Add a query parameter to your GET
/api/northcoders
endpoint that searches for northcoders with a specific job. e.g. all the block-leads or all the marketing team. How should the endpoint respond by default (i.e. when not provided the query parameter?) How should it behave when provided an invalid parameter? What status code should your server respond with? -
Add a GET
/api/pets
endpoint which accepts a query that serves all northcoders who have a living or dead pet -
Add a query parameter to your GET
/api/pets
endpoint that serves all northcoders who have a certain kind of pet (e.g. cat, alpaca, llama etc)