Setting up Post request to create a todo
To create the POST request, if you recall, we have to change the method to POST and the URL will be the same, localhost:3000/todos:
Now, in order for this request to succeed, we also have to pass along a Body tab. This one is going to be a raw JSON body. Here, we can specify the data we'd like to send. In this case, the only data property we're going to send is text, and I'll set this to Something to do from postman:
{ "text": "Something to do from postman" }
Now, we can go ahead and fire this off, and down below we get our newly created Todo with a 200 status code:
Which means everything went well. We can save this to our collections so we can easily rerun this one later. I'm going to change the Request Name to POST /todos, following that same syntax. Then, I can then select an existing collection, the Todo App collection, and save it:
Now I can simply click the request, using command + enter, or clicking the Send button, to fire off the request, and I get my todos array—everything looks great.
I can always click POST, add a second one, tweak it if I like, adding the number 2, and then I can use command + enter to fire that one off. I can rerun the GET request and I have my two todos in the database:
With this in place, our GET /todos request is now complete. We also set up our collection in Postman, making it really easy to fire off any of these HTTP requests much faster.
I'm going to go ahead and wrap this section up by making a commit over in the Terminal. I'm going to shut the server down and run git status. This time around, you'll see that we just have one file and it is modified, which means instead of using git add, we can simply use git commit with the -a flag. The -a flag adds all modified files to the next commit. It does not work for new, untracked files, but modified files are perfectly fine. Then, I can tack on the -m flag to specify my commit message. A good one for this will be Add GET /todos route:
git commit -a -m 'Add GET /todos route'
Last up, we're going to push it up to GitHub using git push, and now we are done. In the next section, we'll write test cases for GET /todos.