Last active
December 17, 2020 17:48
-
-
Save matchy233/494ceb7bb01bd3fade7042eb13e20423 to your computer and use it in GitHub Desktop.
Reading request body of Content-Type text/plain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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