02 - Refactor
In this module, we'll refactor the user create controller method.
Refactor
Refactoring is just part of the game. We work in iterations. You write methods, you add to them, you take things away. In this chapter, you won't be rebuilding a POST controller method in seven steps like we did last time. Let's do a quick refactor:
Analysis
Along with the user object that gets returned as JSON, we can send a message in the response.
For the sake of time, we'll ask you to reread and review the flow of the above method. If you don't have an understanding, you'll want to review the information in the testcontroller in the
test/seven
method. One big difference here is that we have two properties instead of one.
Postman
Let's quickly test this iteration of the method with Postman.
1. Start your server then open Postman.
2. Figure out the endpoint to send a post request to.
3. Go to the body tab -> Choose Raw -> Change the dropdown to JSON.
4. Enter the request body: {"user" : { "username": "kenn", "password":"linuxsirad" }}
.
5. You should see the response string:
Postgres
Check Postgres, too:
Next
In the next module, we'll add a token to the response.
Last updated