azrahel
azrahel

Reputation: 1213

Querystring vs. json data in a POST request

I am writing a project in Javascript using node.js, express and mongodb which includes an API for POSTing images to a server.

When GETting them, the necessary parameters goes in querystring, like:

domain.com/api/imgs?firstParam=XXX&secondParam=YYY

Am not sure about best way to send POST data. My ideas so far are :

Send data entirely in the querystring (except base64 encoded img itself which will be in POST data)

Reuse the GET parameters from the querystring (I need to update data in DB), then send the additional parameters with POST

What would be best practice in this situation?

Upvotes: 2

Views: 3447

Answers (1)

alien c0d3r
alien c0d3r

Reputation: 169

It's most common on POST to use JSON.

Off the top of my head here are a few reasons why:

  • querystrings are part of the url and url length has a limitation
  • on querystings you should use url-encode
  • it's rather difficult to have complex data(ex. nested objects or nested arrays even) on querystrings

Upvotes: 7

Related Questions