3

I'm building a RESTful API using Martini and have a hard time accessing the contents of book.json sent to my service via

curl -X POST "http://localhost:8080/books" -H "Content-Type: application/json" -d @book.json

book.json is not a binary file but a simple text file containing a JSON array. How can I access the transmitted JSON? PostForm on the http.Request is empty.

Ralph Caraveo
  • 10,025
  • 7
  • 40
  • 52
Ralf
  • 2,512
  • 4
  • 24
  • 26

2 Answers2

1

I know this is old but you are probably looking for Martini Binding

https://github.com/martini-contrib/binding

m.Post("/contact/submit", binding.Bind(ContactForm{}), func(contact ContactForm) string {
    return fmt.Sprintf("Name: %s\nEmail: %s\nMessage: %s",
        contact.Name, contact.Email, contact.Message)
})
Luis
  • 96
  • 1
  • 6
0

You probably have data in request.Body that you can demarshal. Imho this aticle explains well the problem: http://nathanleclaire.com/blog/2013/11/30/fear-and-loathing-with-golang-and-angular-js/