Before we jump into building the answers routes, let’s discuss how our answers' objects are related to questions' objects. We will review parent-child relationships and how to use them in this context.
In our API, answers belong to questions because they can't exist without them. 0:00 This is known as a parent-child relationship. 0:04 This relationship will help us structure our routes. 0:07 We want to build a route to create new answers for a question. 0:11 The route will look like this, /questions/:id/answers. 0:16 A developer should send a POST request to this route. 0:22 To edit and delete specific answers, we'll use the following route, 0:25 /questions/:id/answers/:id. 0:32 Sending a PUT or DELETE request to this route will accomplish the update, and 0:36 delete actions on that answer. 0:41 Finally, we need to give our users a way to vote on answers. 0:44 Let's make two routes for voting, a vote up and a vote down route. 0:48 We can build them on to the individual answer routes, 0:53 since the act of voting belongs to one answer. 0:57 So the two routes would be /questions/:qID/answers/:aID/ and 1:00 then vote-up or vote-down. 1:06 These two actions represent users casting their own vote. 1:09 We should use a POST request. 1:13 Great job. 1:16 We've done a huge amount of work so far. 1:17 Every API you'll see in the wild will do things just a little differently. 1:20 You can certainly build this API in a different way. 1:24 Trying to keep the developers who will use your API in mind 1:28 will help inform your design process. 1:31 Coming up, we'll code the Express app that will serve our API. 1:34
You need to sign up for Treehouse in order to download course files.Sign up