When developing a REST API, is it ok to use Form-Data in POST requests or is that frowned upon? All my methods return a JSON body or only an HTTP code, should this be extended to my POST and PUT requests as well? I think that Form-Data is a lot easier to work with, but that might just be that I'm a bit new to developing REST APIs.

  • If you want to strictly conform to REST semantics, you will only use POST for those things that aren't covered by a GET, PUT or PATCH. However, most applications don't require this level of rigor. I have worked for companies that have successfully created APIs using only POST, and the APIs of many large companies are not fully REST compliant. Apr 10 '20 at 15:20

When developing a REST API, is it ok to use Form-Data in POST requests or is that frowned upon?

The ur example of REST is the world wide web, where we posted application/x-www-form-urlencoded documents to the server and received text/html responses.

So decoupling the request representation from the response representation should be fine.

From a REST perspective, the more interesting question is "how does the client know which key value pairs to include in the request body?" On the web, we had HTML forms, which allow you to describe to a general purpose component how the request payload should be constructed. Without that piece, if you are using out of band communication to tell bespoke clients how to create the request payloads, then you aren't really doing REST.

(Which, by the way, is fine -- if you don't need the REST properties, then you can relax the corresponding constraints. Document exchange protocols described out of band isn't the REST architectural style, but it can get the job done.)


I don't think so. REST API != JSON API.

However, you should consider your clients. I am assuming web browsers are one type of client, since you mention Form Data. This is easy to create in a browser, but I don't think it's as easy to create in an Android or iOS app (I could be wrong here). If you want to target those devices also, you may want to look back in to using JSON.

  • Thanks! I hadn't really considered iOS and Android apps, and that FormData might not be as easy to implement there as on the web. Maybe I'll have a go at implementing methods that can handle both FormData and JSON
    – BaraKanske
    Apr 10 '20 at 16:29
  • Don't start implementing. Send your iOS and Android developers an example of a medium complex FORM request and see what they tell you.
    – gnasher729
    Apr 12 '20 at 9:22
  • Unfortunately, I don't have any other developers, this is just a personal project. I'm trying to make a website with a Java backend that communicates with a REact frontend through a REST API. I don't know if this is a bit overkill, but it's just for learning purposes so it's probably best if it is.
    – BaraKanske
    Apr 20 '20 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.