Insertion continued

GetGoing: Introduction to Golang Introduction to API development with Go
5 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
This is a free item
$0.00
د.إ0.00
Kz0.00
ARS$0.00
A$0.00
৳0.00
Лв0.00
Bs0.00
B$0.00
P0.00
CA$0.00
CHF 0.00
CLP$0.00
CN¥0.00
COP$0.00
₡0.00
Kč0.00
DKK kr0.00
RD$0.00
DA0.00
E£0.00
ብር0.00
€0.00
FJ$0.00
£0.00
Q0.00
GY$0.00
HK$0.00
L0.00
Ft0.00
₪0.00
₹0.00
ISK kr0.00
¥0.00
KSh0.00
₩0.00
DH0.00
L0.00
ден0.00
MOP$0.00
MX$0.00
RM0.00
N$0.00
₦0.00
C$0.00
NOK kr0.00
रु0.00
NZ$0.00
S/0.00
K0.00
₱0.00
₨0.00
zł0.00
₲0.00
L0.00
QR0.00
SAR0.00
SEK kr0.00
S$0.00
฿0.00
₺0.00
$U0.00
R0.00
ZK0.00
Already have an account? Log In

Transcript

Everyone, in this video, we're going to be completing our endpoint which we left in the last video. So, take a look at this create to do function. So let us pass some arguments through it. So we want name. And we want to do both to get the type string. Now, rather than hard coding these values, we can simply say name.

And to do to save in the database. So now we need to change over here. So now this needs name. And to know where are we going to get this data from. So we're going to be getting getting this data in the form of JSON from the front end in the form of API call. So in postman, just select this post option, go to body, select raw.

Then from this drop down menu, select JSON. Now, what do you write will be formatted as JSON so we want to meet him and we wanted to be younger and we wanted to do And we want it to be from postman, or anything like that. Or let's say buy groceries. So if you send a request down this path, then they should return a response accordingly. And the status code should be 201, which is great. Now, you remember, if you remember in last video, when we were talking in the last two or three videos when we were talking about ping, then we talked about how we can encode and serialize JSON structure.

So now we're going to be talking about decoding the same structure. So let us create a request in the structures in the view. So I'll create a time post request. Now in the post request, you want the name to be of type string, and to also be of the type string Now I can add my JSON tags. My JSON is more a name and overheads more easy to do. So basically what is going to happen is what is going to happen is that it's going to look at the JSON is going to say that, okay?

So utilize whatever DC realize whatever small name, and you have into the capital name and structure. And we're going to do the same thing for two. Now we have a POST request ready? Let's go to controller. And then let's create a structure for it. So I can do something like data is equal to views, dot post request, and empty.

Then I want to deserialize the data from via request into this so I can do a JSON dot new decoder. Now whatever I'm decoding gets decoded from the Request r dot body. And I will decode it in my new structure by passing it as reference. So now whatever data I received in the form of JSON request is now in my structure data. Now I can simply do data dot name, dot dot two, to accessing sweets. So now, if you take a look at our postman, we're sending a POST request.

So, we're going to change from intergate to method post. And then we're going to say, okay, whatever data we get, I want to print it out. And then, after printing the data out, I'm gonna write a header, which is gonna say, HTTP ports. So it's gonna let the front end know that or everything was created. And along with that, I want to send the JSON of the newly created document. I'm going to do a JSON dot new encoder.

And are your latest ones, right? And then ENCODE data. So let's see what happens over here. I'm gonna do a quick golden mean. And then I'm gonna see by anything by a mouse. See, here, we got our JSON back, if you don't want to look at look at it in the JSON format, and simply do this.

And then we go to one created status code. So if you take a look at your SQL collection, uses MySQL. And then I can do a select star from to do. And we go down by mouse from this. So in this video, we learned how to send a POST request and then converted, set or pass it as an argument to the Create function to the model and then we created our To do according to the block specification, or the to do specification over here. So in the next couple of videos, we're going to be learning about how we can read all entries, read all entries by ID, and how we can even delete entries.

So thank you guys. Stay tuned and see you guys in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.