Created
January 18, 2021 08:50
-
-
Save ProfAndreaPollini/d43ad730774f5c9e95c445c55b1e477d to your computer and use it in GitHub Desktop.
materiale lezione 18 1 2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express") | |
const app = express() | |
// elenco di tutti i dischi: GET /vinyls | |
app.get("/vinyls", (req, res) => { | |
res.send([ | |
{ | |
titolo: "disco 1", | |
autore: 1 | |
}, | |
{ | |
titolo: "dsico 2", | |
autore: 2 | |
} | |
]) | |
}) | |
// elenco degli autori: GET /authors | |
app.get("/authors", (req, res) => { | |
res.send([ | |
{ | |
nome: "pinco pallo", | |
id: 1 | |
}, | |
{ | |
nome: "test", | |
id: 2 | |
} | |
]) | |
}) | |
// elenco dei generi: GET /genres | |
// recuperare informazioni su un disco GET /vinyls/234 | |
app.get("/vinyls/:id", (req, res) => { | |
const { id } = req.params | |
// TODO: recupero dettagli vinile richiesto | |
// ritorno valori al client | |
res.send({ | |
titolo: "disco 1", | |
autore: 1 | |
}) | |
}) | |
// recuperare tutti i dischi di un autore GET /authors/2/vinyls | |
// recuperare i dischi di un genere GET /genres/1/vinyls | |
app.listen(9999, () => { | |
console.log("it works!") | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment