This is my first NodeJS server and a code challenge from a class in Rocketseat's Bootcamp. The challenge involves creating a REST API server from scratch using express. Read Description
Build a node server from scratch using Express and Nodemon.
-
POST /projects
: This route creates a new project and must receiveid
andtitle
in the body. The result will be a json response in the following format:{ id: "1", title: 'Novo projeto', tasks: [] }
. -
GET /projects
: This route will list all projects with their respective tasks. -
PUT /projects/:id
: This route receivesid
as a parameter and allows user to update only the project's title. -
DELETE /projects/:id
: This route receivesid
as a parameter and allows user to delete the project and respective tasks. -
POST /projects/:id/tasks
: This route receivesid
as a parameter to identify a specific project, and allows user to creat a new array of tasks.
-
Create a middleware that validates if a project with a specific ID exists. This middleware is to be used only on the routes that receive
id
of the project as a parameter. Return an error if the project does not exist, otherwise, allow the request to function as normal. -
Create a global middleware that intercepts all requests and prints with a (
console.log
) the amount of requests made by the application.
If route POST /projects
is called with { id: 1, title: 'Novo projeto' }
as body and route POST /projects/1/tasks
with { title: 'Nova tarefa' }
, your response should be an array of projects in the following format:
[
{
id: "1",
title: "Novo projeto",
tasks: ["Nova tarefa"]
}
];
To run the application first install dependencies
yarn or npm install
Then run the application
yarn dev
Your code should be up and running here
http://localhost:3000
Check out NodeJS Authentication Challenge here.
This project is made available under the MIT LICENSE.