mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
9f85b74fc9
Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
45 lines
809 B
Go
45 lines
809 B
Go
package main
|
|
|
|
import (
|
|
"github.com/kataras/iris"
|
|
"github.com/kataras/iris/context"
|
|
)
|
|
|
|
type Company struct {
|
|
Name string
|
|
City string
|
|
Other string
|
|
}
|
|
|
|
func MyHandler(ctx context.Context) {
|
|
c := &Company{}
|
|
if err := ctx.ReadJSON(c); err != nil {
|
|
ctx.StatusCode(iris.StatusBadRequest)
|
|
ctx.WriteString(err.Error())
|
|
return
|
|
}
|
|
|
|
ctx.Writef("Received: %#v\n", c)
|
|
}
|
|
|
|
func main() {
|
|
app := iris.New()
|
|
|
|
app.Post("/", MyHandler)
|
|
|
|
// use Postman or whatever to do a POST request
|
|
// to the http://localhost:8080 with RAW BODY:
|
|
/*
|
|
{
|
|
"Name": "iris-Go",
|
|
"City": "New York",
|
|
"Other": "Something here"
|
|
}
|
|
*/
|
|
// and Content-Type to application/json
|
|
//
|
|
// The response should be:
|
|
// Received: &main.Company{Name:"iris-Go", City:"New York", Other:"Something here"}
|
|
app.Run(iris.Addr(":8080"))
|
|
}
|