completed 3.3

This commit is contained in:
counterweight 2025-06-01 13:41:45 +02:00
parent 3809ba2c83
commit f85b066241
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 21 additions and 2 deletions

View file

@ -30,10 +30,28 @@ app.get("/api/persons", (request, response) => {
response.json(persons);
});
app.get("/api/persons/:id", (request, response) => {
const requestedId = Number(request.params.id);
const requestedPerson = persons.find(
(person) => Number(person.id) === requestedId
);
if (!requestedPerson) {
return response.status(404).json({
error: "ID not found.",
});
}
if (requestedPerson) {
return response.json(requestedPerson);
}
});
app.get("/info", (request, response) => {
let responseString = `<p>Phonebook has info for ${persons.length} people</p>`;
responseString += `<p>${new Date().toString()}</p>`;
const id = request.params.id;
response.send(responseString);
});

View file

@ -0,0 +1 @@
GET http://localhost:3001/api/persons/6