Ralf
Ralf

Reputation: 2642

Accessing JSON received via POST from file

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.

Upvotes: 3

Views: 268

Answers (2)

Luis
Luis

Reputation: 96

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

Upvotes: 1

user614956
user614956

Reputation: 1

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/

Upvotes: 0

Related Questions