You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's start with a simplified version of the `PUT /api/snippets/:id` route. First we add the PUT route to `api/snippets.js`:
6
+
7
+
```js
8
+
// ...
9
+
10
+
// PUT /api/snippets/:id
11
+
router.put("/:id", async (request, response) => {
12
+
// TODO
13
+
});
14
+
15
+
// ...
16
+
```
17
+
18
+
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.
19
+
20
+
The PUT request we want to make will look something like this:
21
+
22
+
```text
23
+
PUT /api/snippets/1
24
+
{
25
+
"title": "Updated snippet title",
26
+
"contents": "#hello world",
27
+
"is_private": true
28
+
}
29
+
```
30
+
31
+
### Exercise: Implement the PUT endpoint
32
+
33
+
When we now make a request like:
34
+
35
+
```text
36
+
PUT /api/snippets/1
37
+
{
38
+
"title": "Updated snippet title",
39
+
"contents": "#hello world",
40
+
"is_private": true
41
+
}
42
+
```
43
+
44
+
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.
45
+
46
+
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).
0 commit comments