I want to build a rest app in which I have to get the values that are sent by post as xml. How is the data recovered?
I'm using echo framework.
I want to build a rest app in which I have to get the values that are sent by post as xml. How is the data recovered?
I'm using echo framework.
You'll want to use the Binding functionality of Echo, in combination with struct tags to provide the names you expect the XML keys to be.
type DoThingRequest struct {
Name string `xml:"name"`
}
e.POST("/do_thing", func(c echo.Context) (err error) {
body := new(DoThingRequest)
if err := c.Bind(body); err != nil {
return
}
// Do some stuff...
}
See https://echo.labstack.com/guide/binding/ for more information and options for binding.
you can use following function, where "value" corresponds to wrapper tag name.
func xmlEndpoint(c echo.Context) error {
// get xml from request body
xml := c.Request().Body
// parse xml
var data map[string]interface{}
if err := xml.Unmarshal(data); err != nil {
return err
}
// get value from xml
value := data["value"].(string)
}