Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
@@ -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.