Golang Web - HTTP Method: GET & POST

egaprsty

Ega Prasetya

Posted on September 6, 2020

Golang Web - HTTP Method: GET & POST

A route handler usually accepts any type of request, in that sense: regardless of the type of HTTP method, it will still enter one handler (such as POST, GET, etc.).

PRACTICE

So learn and practice this code.

Alt Text

Struct *http.Request have a Method name material that can be used to check the method rather than the Request that`s in motion.

In the above example, the request to the route / method POST will generate the text POST output, while the method GET will produce the text GET output.

TEST

Use the POSTMAN or tools to encourage testing. Here is a sample of the request by Method GET.

Alt Text

While below is Method POST

Alt Text

If the method is instead of the GET and POST, then per the source code above, the request should have produced a response 400 Bad Request. Below are the example of the request by method PUT

Alt Text

So finally! Enjoy it.

💖 💪 🙅 🚩
egaprsty
Ega Prasetya

Posted on September 6, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Golang Web - REST API With Mux
go Golang Web - REST API With Mux

September 10, 2020

Golang Web - HTTP Cookie
go Golang Web - HTTP Cookie

September 9, 2020

Golang Web - Form Upload File
go Golang Web - Form Upload File

September 8, 2020