Send "Content-Type": "application/json; charset=utf-8" by default
See original GitHub issueHey folks, first of all great job with the library 😃
So I notice that ember-ajax sends data with a content type of application/x-www-form-urlencoded
by default. Since sending JSON is so common, would you think it’s a good idea for application/json
to be the default content type instead? (Like in superagent.)
For example, instead of this:
this.get('ajax').post(url, {
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
hello: 'world',
foo: 'bar'
})
}
You could do something like this:
this.get('ajax').post(url, {
data: {
hello: 'world',
foo: 'bar'
}
})
I’m thinking it would just cut down on some boilerplate. What do you think?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:8
Top Results From Across the Web
What does "Content-type: application/json; charset=utf-8 ...
Content -type: application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding is ...
Read more >encoding for Content-Type application/json should be UTF-8 ...
The MIME media type for JSON text is application/json. The default encoding is UTF-8. (Source: RFC 4627).
Read more >Content-Type - HTTP - MDN Web Docs - Mozilla
In requests, (such as POST or PUT ), the client tells the server what type of data ... Content-Type: text/html; charset=utf-8 Content-Type: ...
Read more >Make default charset UTF-8 when using `receiveText` for ...
Request with Content-Type: application/json is decoded not as UTF-8, while request with Content-Type: application/json; charset=utf-8 is decoded correctly.
Read more >What does “Content-type: application/json; charset=utf-8 ...
Content -type: application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding is ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yep, just tried it out - looks great! @cqcsobreyra’s idea is good, here’s the custom
AjaxService
I made to support my original use case:Usage:
Just wanted to share an idea for a quick dirty fix how to achieve default options for those who might find it useful. In the ajax service you could do something like
And then just call this.get(‘ajax’).configuredRequest(‘/yoururl’, yourOptions);