JSON is (by far) the most flexible and modern option of the two, so I would go for that. Especially if you have already decided to return a response in JSON.
That said, there's no reason you can't support both, if this is beneficial for the consumers of your API. HTML forms submit their content with an HTTP request where the Content-Type
HTTP header will be set to application/x-www-form-urlencoded
, while the correct content type for JSON is application/json
.
Some frameworks, e.g. ASP.NET Web API offer some automatic serialization of the incoming request (whether it is XML or JSON, I'm not sure if this framework supports form encoding), lifting the burden of this task from you.
If you're creating REST APIs, you can use the Swagger specification; it's a definition format (YAML) to describe RESTful APIs creating an interface for easily developing and consuming an API by mapping the resources and operations associated with it. It's language agnostic so you can generate services for many Server/Client-side languages, it's readable, and above all generates a nice API specification documentation.