In this challenge, a server is develop with Express that uses the File System module to add, modify and delete songs stored in a local JSON called repertory.json
The server provides the following routes:
POST: /songs
: Receives the data of a song and adds it to the repertoryGET: /songs
: Returns a JSON with the songs registered in the repertoryPUT: /songs/:id
: Receives the data of a song to be edited and updates it by manipulating local JSONDELETE: /songs/:id
: Receives the id of a song and removes it from the repertory.
The client application that consumes the routes is located in the file index.html, inside the public folder. To use it: run server and CTRL + right-click on the path displayed in the terminal, or open localhost:4000
in your navigator after the server is up
- POST: Fill in the 3 fields and click on add.
- PUT: Click on the edit button of the song you want to modify, the form will be replaced by the data of the selected song, modify the desired fields and then click on edit.
- DELETE: Click on the delete button of the selected song.
Using Thunder Cliente for VS Code as a client application
METHOD: GET
ENDPOINT: localhost:4000/songs/
To add a song, the following structure must be followed (the id is generated with nanoid, so, to create a song you don't need to write this data):
METHOD: POST
ENDPOINT: localhost:4000/songs/
BODY JSON
{
"title": "",
"artist": "",
"tone": ""
}
To modify a song:
METHOD: PUT
ENDPOINT: localhost:4000/songs/{id}
BODY JSON
{
"title": "",
"artist": "",
"tone": ""
}
To delete a song:
METHOD: DELETE
ENDPOINT: localhost:4000/songs/{id}