0

Which encrypt value for request POST header when designing a RESTful API for an SPA application?

  • application/x-www-form-urlencoded
  • multipart/form-data
  • text/plain
  • application/json
Jason Aller
  • 3,391
  • 28
  • 37
  • 36
user2080105
  • 1,303
  • 3
  • 15
  • 25
  • What motivates this choice and how that would help me over other choices ? – user2080105 Jan 16 '17 at 09:12
  • All of them can be good choices, depending on your needs. JSON is probably a good default, but there is a place for others too. – Evert Aug 27 '20 at 04:03

2 Answers2

1

JSON yes, application/json ... not so much. If you just use application/json, your payloads aren't self-descriptive, after all - so you still have strong coupling between both endpoints. Thus, I would recommend to define JSON based media types for each type of message.

Julian Reschke
  • 35,455
  • 7
  • 78
  • 83
0
  • application/x-www-form-urlencoded

For application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one giant query string -- name/value pairs are separated by the ampersand (&), and names are separated from values by the equals symbol (=)

(application/x-www-form-urlencoded or multipart/form-data?)

  • multipart/form-data

With this method of transmitting name/value pairs, each pair is represented as a "part" in a MIME message -For short alphanumeric values (like most web forms), the overhead of adding all of the MIME headers is going to significantly outweigh any savings from more efficient binary encoding

(application/x-www-form-urlencoded or multipart/form-data?)

  • text/plain

This is "not reliably interpretable by computer", so it should never be used in production, and we will not look further into it.

(What does enctype='multipart/form-data' mean?)

Community
  • 1
  • 1
Van
  • 581
  • 3
  • 11