Skip to content

lilithrv/intro-express-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Desafio Latam: Introduction to Express Js

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 repertory
  • GET: /songs : Returns a JSON with the songs registered in the repertory
  • PUT: /songs/:id : Receives the data of a song to be edited and updates it by manipulating local JSON
  • DELETE: /songs/:id : Receives the id of a song and removes it from the repertory.

Client Application

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}

Backend


Dependencies

  • Framework Express
  • ID generator for JavaScript Nano ID
  • To install dependencies run: npm install
  • devDependencies Nodemon for run server and automatically restarting the node application when file changes, in the terminal run: npm run dev

Releases

No releases published

Packages

No packages published