Closed Bug 844451 Opened 11 years ago Closed 8 years ago

sending json in post requests should be easier

Categories

(Add-on SDK Graveyard :: General, defect, P2)

x86
macOS
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: glind, Unassigned)

Details

for POST would it be nice to:

* stringify content differently (by JSON.stringify)
* auto set Content-length?

Did this exist in the past somewhere? I am having Twilight Zone memories that POST used to do more guessing around this but I can't find the code :)
I don't remember it ever doing that, IIRC we've always had to set the content type at the least. Are you saying you have to also set the content length? Ideally, what would your code look like for a JSON / POST request?
Flags: needinfo?(rFobic)
Priority: -- → P2
After looking through the code, it looks like I was confused / surprised about what happens if you put an object as `request.content`.

Now, it attempts to `stringify` it, which implies "GET/POST FORM" is the expected use case.  I expected it to `JSON.stringify` it.  Both seem like valid approaches.  I wonder if the api should be more explicit?

* request.form - queryargify if object, or fail.
* request.json' - jsonfiy, error if fail.  content/type to applicaton/json
* request.content - 'content' as "exactly this string"
Changing this API now would mean breaking it, and I don't think it's worth it. Also as far as I know API was modeled after jQuery API so it should not be surprising to people used to it.

I don't mind adding `request.json` and `request.form` in addition, but then we'll have to handle case where users put both and I don't have any good answer for what
should happen then.
Flags: needinfo?(rFobic)
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.