0

I am using node.js restify.

There are 2 ways to read parameters from HTTP GET.

  • Reading query variables.

enter image description here

  • reading body variables.

enter image description here

What is the difference between the 2? Under what situation should one use which?

guagay_wk
  • 26,337
  • 54
  • 186
  • 295

2 Answers2

4

Based on the standards that we have been using, I would say that a best practice would be that you should use params when doing a get, but use body for post, put and delete. Cause doing post/put etc you may need to send more complex data to your end point.

Also, found this: You can fit more (diverse) data in the body than in the url. You can pass any string (special characters) in the body, while encoding them in the url would get you vulnerable to status 414 (Request-URI Too Long). And it's a lot easier to use the body when passing arrays and complex objects :)

CodePhobia
  • 1,315
  • 10
  • 19
1

The difference in user experience is, using get, the page can be bookmarked with the parameters. That is something that is not possible with post. That might be desirable or not, depending on the scenario, but it is definitely something to think about and making a decision about get/post.

bdifferent
  • 703
  • 4
  • 12