Lesson 09
Courses / Quick Start Introduction to Sails
Using Postman to Test the Sails Blueprint API

Video Transcript

So let's go back to Postman. So we got our local host at the part 1337. So we created a resource called Company. So by default, Sales uses a singular resource name. All right? It can be changed to Plural. All right? But let's go with the singular for now. So if you say about get slash company, that should give you a list of all the companies. So we got an empty list, as you can see, because we don't have any record, obviously. Now let's create a company record. So let's switch from get to a post request. Now here in the post request, we want to send some data. So let's go to the body tab, and let's choose no, not form data, but let's choose raw. And let's switch from text to JSON. OK? So we're dealing with JSON, JSON RESTful API. Let's go JSON all the way. So for the body of the post request, raw JSON. So let's make a JSON here, open braces, and let's write, let's create a code. Create a company. So a company has a name. Let's say the name. I don't know. App. App. Blah, blah. Note that we're using JSON, so make sure you have the double quotes for the property. We're using JSON, so we need that. A company also has a founding date. So for the format for the date, sales understands the format, the double digit year followed by a dash, double digit month followed by a dash, double digit day. So let's say a company has found in the year of 1980. And a certain company, the month was April, and the day was 11. So this format is accepted. The sales will understand this format for the date. And now a company also has in our example employee count. And that's just an answer. Let's say it has, I don't know, 483 employees. Notice that I'm using JSON, so if you are used to typing commas all the time for property objects, don't type one here because JSON, this is not valid JSON, so no commas there for the last property. So with that in mind, we're going to create this company called Apple, blah, blah, founded in 1980, April 11th, 483 employees. So let's click send and see what happens. So down here, I got my response. If I scroll down, so this is the response from sales. It gave me a status 201 created. And if I try to zoom in here for you to see better, here's the response, JSON response. So notice it created my record with the information I provided, as well as now it has an ID number 1, because it's now in the database, in this case, local disk database. And notice that sales by default also adds this created ad and updated ad timestamp properties. So notice the format here is always a date followed by time, no matter what. So this is the format that sales uses. I think this is called the ISO format. Correct me if I'm wrong. Please live in the post, comment if you know about this format. Anyway, so sales created a record for us, a company record. It assigned an ID and it started in the database and also created by default these timestamp properties. So notice we did not have to specify in the model, if we go back to the API slash model slash company, we did not specify ID, and we did not specify those created ad and updated ad timestamps. So sales does it by default. So you automatically get those things. All right. So going back to postman. So there you go. That's the response from sales. So this is it for this lecture. Next lecture, we're going to learn more about the other routes and the other requests. Let's play more around, play more with these requests and see you then.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: