-1

I'm working on web application where I need to send some data using ajax with post method. So I have two choices to send data whether in JSON format or query prams. I'm confused which should I use? and is it safe to send data in JSON format?

PK Kulhari
  • 13
  • 3
  • sending data in the body is a bit safer than sending it in the query params... if you use HTTPS and send data in the body of a POST request it's pretty safe – lucasreta Feb 22 '21 at 05:03

1 Answers1

0

As @lucasreta mentioned, if you use HTTPS, it doesn't really matter either way.

Both methods are widely used. I know that Google accepts a Post request with query params and responds with a JSON object for ReCaptcha Server side validation.

Sometimes, the decision to use one or the other (or both) is dependent on how easy your chosen back-end technology makes it for you to either parse out query params or serialize JSON.

I will say that there is a general trend in using JSON in the request body as opposed to query params.

I found a couple of SO questions that are more down the lines of what you are asking...

REST API Best practices: args in query string vs in request body

REST API Best practices: Where to put parameters?

Apologies for a lot of edits, my mind was racing. The question is a tad ambiguous.

spencer741
  • 350
  • 3
  • 15