IcaroPeretti

Express routes

Jun 10th, 2021
563
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.get("/courses", (request, response) => {
  2.   const query = request.query;
  3.   console.log(query);
  4.   return response.json(["Curso 1", "Curso 2", "Curso 3" ]);
  5. });
  6.  
  7. app.post("/courses", (request, response) => {
  8.   const body = request.body;
  9.   console.log(body);
  10.   return response.json(["Curso 1", "Curso 2", "Curso 3","Curso 4" ]);
  11. });
  12.  
  13. //PUT - Alterar dados no servidor
  14. app.put("/courses/:id", (request, response) => {
  15.   const {id} = request.params;
  16.   console.log(id);
  17.   return response.json(["Curso 6", "Curso 2", "Curso 3","Curso 4" ]);
  18. })
  19.  
  20. //PATCH - Alterar informação especifica
  21. app.patch("/courses/:id", (request, response) =>{
  22.   return response.json(["Curso 6", "Curso 7", "Curso 3","Curso 4" ]);
  23. })
  24.  
  25. app.delete("/courses/:id", (request, response) =>{
  26.   return response.json(["Curso 6", "Curso 2","Curso 4" ]);
  27. })
RAW Paste Data