artvolk
artvolk

Reputation: 9528

Format of REST incoming data: POST fields or JSON?

In most examples I saw the incoming data (for example for creating new entity) data is POST'ed as form encoded. This is great for 'flat' objects, but I need to transfer more complex objects (2-3 levels of nesting). Is it acceptable to transfer them in the body of POST request as JSON-encoded string?

Upvotes: 0

Views: 402

Answers (3)

suing
suing

Reputation: 2878

json and form-data are media types. Pick what you want and be sure to set the content-type to the one you've chosen.

Upvotes: 1

user468648
user468648

Reputation: 197

I believe JSON is commonly used to communicate arrays within the body of a document. I am using it here to transfer this array of mapped points and associated attributes http://ageara.com/test/map-service.php?action=listpoints ... albeit not with REST style ;-)

Upvotes: 0

user647772
user647772

Reputation:

As long as you set the proper header to application/json and generally use the HTTP mechanisms of content negotiation: yes, this is acceptable.

Upvotes: 3

Related Questions