-3

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

2 Answers2

1

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.

Noah Stride
  • 402
  • 2
  • 9
0

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)
}