DEV Community

Ega Prasetya
Ega Prasetya

Posted on

4 1

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️