Glide
Glide

Reputation: 21255

Common practice to HTTP Form POST a JSON string instead of using key/value fields?

Is it a common practice to create an HTTP POST end point (with the header "application/x-www-form-urlencoded") that takes in a JSON string as the value of the key/value POST data instead of having a list of fields as the POST data? Regardless of being common or not, is it considered bad since it requires more work to stringify the fields into a JSON string?

Example: user={"username":"bob", "age":1} vs username=bob&age=1 in the POST form data.

Upvotes: 0

Views: 195

Answers (1)

Fenton
Fenton

Reputation: 251152

This is actually very common - the SOAP messaging format does just this; replacing the standard POST body with a custom messaging format (in the case of SOAP it is XML).

The only thing to consider is that HTTP is pretty ubiquitous these days and although it is trivial to find a JSON library for any language, creating a HTTP body is utterly simple.

So it isn't bad by any means, but if the client is serializing to JSON and then you are deserializing from JSON, would it just be easier to use standard HTTP message bodies?

Upvotes: 1

Related Questions