Category
📚
LearningTranscript
00:00Let's get back on it and let us test this out.
00:04I'm just going to run without debugging,
00:06so that it loads a bit more quickly,
00:09and we're just going to use Swagger tool to test this API.
00:13Now, an alternative to Swagger would have been
00:16like Postman or something similar to that,
00:19but Swagger is capable,
00:21so we'll just use it right now.
00:23When we expand our get,
00:26that implies that we'll be getting back a collection.
00:30We'll see the sample object of what we'll be getting back,
00:34and notice the square braces that depicts
00:37that it will be an array, right, of objects.
00:41Let us try it out and execute,
00:44at which point it actually goes and queries the database,
00:47and there are all of the sample cars
00:51that we would have entered, right?
00:54Now, if I try to get by ID, let me try that one.
00:59So try it out, it says, give me the ID, I'll give it 10,
01:02and we get back the 200 response with the car with the ID 10.
01:08If I try it with 100, I don't have 100 cars,
01:11so this time I get back that 404,
01:13because it couldn't find that car by that ID, right?
01:17And you can pay attention to the response URLs,
01:20namely, this is what you call the base URL,
01:24because that's a server,
01:25and then this will be the path,
01:26and then that will be our ID value going over, right?
01:31So it's good to pay attention to these little things,
01:33because when we're writing code to interact with the API,
01:36we have to mimic these kinds of URLs.
01:40So that verifies that our get by ID works.
01:44Let's try the put.
01:45So if I try to modify car with ID one,
01:50and let's say I make it into string, string,
01:54so let me first retrieve the car with the ID one,
01:56so we can see what it looked like.
01:59So that is the car with the ID one.
02:01Let me take a quick copy of it.
02:03It's a Honda Fit Vinny's ABC.
02:06Now, when I run this,
02:09I notice I would have to put in all the details
02:12I intend to update with.
02:13So if I leave the defaults and click execute,
02:16it's going to tell me no content,
02:18which means it was successful.
02:20If I attempt to retrieve this car again,
02:23then I'm going to see that it is not working.
02:30Let's set the code.
02:33And, oh, my bad.
02:36Oh, this is my silly mistake.
02:38So I actually mixed up the assignments.
02:41So I should have been assigning record,
02:45the values coming in through car.
02:47So I apologize for that.
02:49Mix up, and I have on my hot reload on save.
02:52So I should be able to just go back and try again.
02:56So let's execute.
02:57We're seeing one Honda Fit and everything.
03:01And then when I try to execute here,
03:05I get the 204.
03:08So now I'm seeing, there we go.
03:12So now we're seeing everything change the string.
03:16My silly mistake, guys.
03:17So that works.
03:19And that's why testing is important, right?
03:22So let me just revert to my original payload
03:26and then execute again.
03:29And then we can verify that we now see the original data.
03:33Right, looking good.
03:35And then the final one is the delete.
03:39So which one would I want to delete?
03:40Let us delete, I'm not,
03:45I don't want to say what kind of car I'm not fond of,
03:48but I'm going to delete the one that I'm least fond of
03:52in this list.
03:54And that would be the car with the ID four.
03:59A bit too small for my taste.
04:01So there we get the 204 that suggests
04:04that it was completed successfully.
04:06So if I go back and execute,
04:08there is no longer a car with the ID four.
04:11And just like that, our CRUD works.