diff --git a/courses/backend/node/week2/session-materials/08-put-endpoint.md b/courses/backend/node/week2/session-materials/08-put-endpoint.md index db0ece7f..c954aa33 100644 --- a/courses/backend/node/week2/session-materials/08-put-endpoint.md +++ b/courses/backend/node/week2/session-materials/08-put-endpoint.md @@ -1,3 +1,46 @@ # PUT endpoint -TODO +## `PUT /api/snippets/:id` + +Let's start with a simplified version of the `PUT /api/snippets/:id` route. First we add the PUT route to `api/snippets.js`: + +```js +// ... + +// PUT /api/snippets/:id +router.put("/:id", async (request, response) => { + // TODO +}); + +// ... +``` + +To be able to update a row in the `snippets` table, we need to have an existing snippet. Create a snippet first and note what the snippet ID is. + +The PUT request we want to make will look something like this: + +```text +PUT /api/snippets/1 +{ + "title": "Updated snippet title", + "contents": "#hello world", + "is_private": true +} +``` + +### Exercise: Implement the PUT endpoint + +When we now make a request like: + +```text +PUT /api/snippets/1 +{ + "title": "Updated snippet title", + "contents": "#hello world", + "is_private": true +} +``` + +you should update the existing row in the `snippets` table with the data from the request body, where the snippet ID matches the `:id` parameter in the URL. + +When updating a snippet we also need to specify a `user_id`. For now, you can just pass in the `user_id` in the request body (alongside the other snippet data). diff --git a/courses/backend/node/week2/session-materials/09-delete-endpoint.md b/courses/backend/node/week2/session-materials/09-delete-endpoint.md index cc83bcee..ba7c15db 100644 --- a/courses/backend/node/week2/session-materials/09-delete-endpoint.md +++ b/courses/backend/node/week2/session-materials/09-delete-endpoint.md @@ -1,3 +1,34 @@ # DELETE endpoint -TODO +## `DELETE /api/snippets/:id` + +Let's start with a simplified version of the `DELETE /api/snippets/:id` route. First we add the DELETE route to `api/snippets.js`: + +```js +// ... + +// DELETE /api/snippets/:id +router.delete("/:id", async (request, response) => { + // TODO +}); + +// ... +``` + +To be able to delete a row from the `snippets` table, we need to have an existing snippet. Create a snippet first and note what the snippet ID is. + +The DELETE request we want to make will look something like this: + +```text +DELETE /api/snippets/1 +``` + +### Exercise: Implement the DELETE endpoint + +When we now make a request like: + +```text +DELETE /api/snippets/1 +``` + +you should delete the row from the `snippets` table where the snippet ID matches the `:id` parameter in the URL.