HTTP methods

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

Hi everyone. In the last video, we made a simple HTTP server. In this video, we're going to be talking about HTTP methods. So our server is running. And let's do a quick code HelloWorld. So if you look at our code of all over again, the odd order request, argument defines a variable called method.

So it states what method you're reaching the server by. So you do a quick, good. And then it's gonna say get. So what am I talking about here? So we're talking about HTTP methods. So if we take a look at this over all over again, whenever a client tries to make a request to the API, how does the API know what kind of requested it is?

Is it update request? Is it a delete request? Does the client want to fetch something does the client want to remove something So those are defined by HTTP methods. So if you do a localhost 3000, if my API is running on localhost 3000, my web applications, then you can say, Okay, I want to get this resource. So default by default, curl sends, get requests. If you open any website, if you open GitHub or Google or any website, then by default, the browser also sends a get request.

Which means that if you go on localhost 3000 over here, and we go on Get going. Then it's going to say hello world. Because we reached a server, and in this case, a browser was acting as a client. But when we were testing over here, goal was acting like a client. So curl also has this property where we can define what methods we want to send by our dash x flag. So I can say I want to send a POST request.

So it's going to take the post request. So let's take a look at the different Types of headers that you can supply. So if you take a look at this article over here, we can see that we've got GET request port before post request, put and delete request. So when we're talking about API's, the records that we're going to use most of the time is get post put. And so get request is when you want to retrieve some information, a POST request is something where you want to post some data either securely, or if you want to post the data in securely, then you can always use get. So what happens is that if you take a look at web pages, then we have forms.

So what happens is whenever we fill forms, we have a choice of any method that we want. But if we do a POST request, on form submission, then those parameters that we enter inside of the forms, the arguments are going are not going to be shown in the URL parameters. But when we do a get, then those parameters are going to be shown in the URL in the URL. So if we're talking about form submissions, and post is the way to go If you're talking about insecure submissions, then get is the way to go. And post. And we have put so put changes the representation of what currently exists in our model layer, which, which essentially means is that okay, if I created a blog blog, and I need to some submit a new blog or update the current blog, with the new submission, then I can do that easily by a put request.

And a delete request is wherever I want to delete anything. So I request all of you to download this post man. So like, we would like we are doing with our curl command and we are doing with a browser where a browser was acting like a client, postman can also act like a client, we can simply do a localhost 3000. And we can do a get going and a get request and it's going to submit one more thing I want to talk about is how multiplexing in go works. So when we're talking about route multiplexing Let's see what happens when we remove the slash. And we just have a get going.

So you do a curl on get going head or you get a you do a curl on get going slash, it's going to say please don't fall because it matches the slash also. So take care while developing GPS that it's also going to match the slash. Now one more cool thing about this is that if you do a slash, and then you do a go run, then it's going to match the closest thing before the slash. So it's going to match get going slash is going to match anything that I type after that and it's going to multiplex it or routed back to slash get going. Because note that we didn't define anything after get going slash. So if we were to do so, I'm just going to copy these lines and I'm going to paste it.

And I'm just gonna say if request comes on, get going slash Go then do something other than HelloWorld do HelloWorld go? No, let's see what happens. Now if I go to get going slash go, it's going to exactly match the exact route. But if you go to get going slash anything other than that, then is a master base route, which is get going. So base route is a keyword which you need to know moving forward. So thank you guys for watching this video.

In the next video, we're going to be talking more about how we can do submissions with GET and POST and how we can access the data from our claims. So we'll see you guys in the next video. Stay tuned.

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.