- Create a simple HTTP services that responds with
Hello world
to every requests:
const http = require('http')
const port = 3000
let test = []
const requestHandler = (request, response) => {
console.log(request.url)
response.end(`Hello world!`)
}
const server = http.createServer(requestHandler)
server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
})
-
Check that this service works with Postman.
-
Change the previous service so it responds with
Hello world
only on the/hello_route
and returns an error with a 404 status code on every other route. -
This is an application for a TODO list. You must add endpoints that will:
-
retrieve the list of tasks
/tasks/
[ { "completed": false, "title": "My task", "content" Implement API", "due_date": "2016-01-04", "created_date": "2019-01-02 "completion_date": null, "id": 1234, }, ... ]
-
get details about a given task
/tasks/1234
{ "completed": false, "title": "My task", "content" Implement API", "due_date": "2016-01-04", "created_date": "2019-01-02" "completion_date": null, "id": 1234, "tags": [ "school" ], "order": 123, "priority": 1, "project_id": 2345, }
-
-
Add an endpoint to delete a task. What should be the URL and the verb used for this?
-
We want to be able to create new tasks, what should be the verb used for that action? Implement this endpoint and test it.
To implement this, you will need to read the body of the request, check out https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/#request-body
-
We want to be able to mark the task as completed without changing its attributes. How can we do this?
-
We now want to attach tasks to users and to projects. What changes need to be made to the current API? Implement them.
-
So far, the user is obligated to create the API endpoints by hand before calling them. Is there another way?
- We want to create a blog and its API. The resources should be:
- authors
- articles
- comments
- images
- tags
We need to be able to create, read, update and delete every resources.
- What should
/authors/12/articles
return? Implement it.
An API is good only when it is used by others. You must build a client for every API you use. Have a look at Node HTTPS module and implement one for each API you did.
Anybody can post and update anything on our API, we must protect it with authentication.