DEV Community

Ega Prasetya
Ega Prasetya

Posted on

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.).


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.


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.

Top comments (0)