Skip to content

Instantly share code, notes, and snippets.

@andygrunwald
Created June 1, 2023 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andygrunwald/269b20e33b0c822693d00429ccdb8693 to your computer and use it in GitHub Desktop.
Save andygrunwald/269b20e33b0c822693d00429ccdb8693 to your computer and use it in GitHub Desktop.
HTTP Methods are just strings ...

Small showcase that HTTP Methods are just strings. This enables you to define your own one.

First, create a small demo webserver. This example is in Go (store the code into a file named main.go):

package main

import (
	"fmt"
	"net/http"
)

func hello(w http.ResponseWriter, req *http.Request) {
	fmt.Fprint(w, "hello\n")
	fmt.Fprintf(w, "Used method: %s\n", req.Method)
}

func main() {
	http.HandleFunc("/hello", hello)

	http.ListenAndServe(":8090", nil)
}

Second: Run it

$ go run main.go

Third, execute HTTP calls:

$ curl -X GET http://localhost:8090/hello
hello
Used method: GET

$ curl -X BEER http://localhost:8090/hello
hello
Used method: BEER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment