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/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?
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./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?
Share Improve this question edited Oct 14, 2014 at 13:14 Zaheer Ahmed 28.6k12 gold badges76 silver badges112 bronze badges asked Oct 14, 2014 at 12:01 azrahelazrahel 1,2232 gold badges15 silver badges32 bronze badges 4- @xShirase ok what code you want ? – Mohammad Sadiq Shaikh Commented Oct 14, 2014 at 12:25
- Edited question itself - should be more understandable now. No code needed for this one in my opinion. Querystring data vs. POST json data. Pretty obvious I think:)? – azrahel Commented Oct 14, 2014 at 12:25
- Agreed, no code is needed. In fact, code would actually add needless noise to the question since the exact implementation doesn't matter. – slebetman Commented Oct 14, 2014 at 14:29
- 1 Agreed, now it's much clearer, thanks for editing my edit ;) – xShirase Commented Oct 14, 2014 at 14:37
1 Answer
Reset to default 7It's most mon 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 plex data(ex. nested objects or nested arrays even) on querystrings