Skip to content

Instantly share code, notes, and snippets.

@matchy233
Last active December 17, 2020 17:48
Show Gist options
  • Save matchy233/494ceb7bb01bd3fade7042eb13e20423 to your computer and use it in GitHub Desktop.
Save matchy233/494ceb7bb01bd3fade7042eb13e20423 to your computer and use it in GitHub Desktop.
Reading request body of Content-Type text/plain
package main
import (
"github.com/labtstack/echo"
)
func main() {
e := echo.New()
// Rquest body is of Content-Type text/plain
// If we use c.Bind(), echo will produce "415 unspported media type"
e.POST("/", func(c echo.Context) error {
b, err := ioutil.ReadAll(c.Request().Body)
if err != nil {
e.Logger.Fatal(err)
}
return c.String(http.StatusOK, string(b))
})
e.Logger.Fatal(e.Start(":2333"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment