Sending JSON API POST request.
See original GitHub issueDo you have a plan to allow (or support) JSON API?
Per the JSON API spec, I have to set 'Content-Type': 'application/vnd.api+json'
, and it looks like it is overridden by application/json
.
api.postJsonApi = function(url, data) {
return this.post(url, data, {
headers: {
'Content-Type': 'application/vnd.api+json'
}
});
};
api
is an instance of axios.
In the request header, it becomes application/json;charset=UTF-8
, probably, it is because the data
is an object.
I set transformRequest
, but I still could not make it work.
api.postJsonApi = function(url, data) {
return this.post(url, data, {
transformRequest: [function(data, headers) {
headers['Content-Type'] = 'application/vnd.api+json';
return data;
}]
});
};
api.postJsonApi = function(url, data) {
return this.post(url, data, {
transformRequest: [function(data, headers) {
headers.post['Content-Type'] = 'application/vnd.api+json';
return data;
}]
});
};
The only way to set the JSON API content type was to add it to the defaults:
var api = axios.create({
headers: {
'Content-Type': 'application/vnd.api+json'
}
});
I was wondering if you know any other way to send the JSON API post with content type application/vnd.api+json
beside adding it to the defaults.
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How do I post JSON to the server? - ReqBin
To send JSON data to the server, you need to provide the JSON data in the HTTP POST request body and pass the...
Read more >Making a JSON POST Request With HttpURLConnection
In this tutorial, we'll demonstrate how to make a JSON POST request using HttpURLConnection. Further reading: Do a Simple HTTP Request in Java....
Read more >How to pass json POST data to Web API method as an object?
You need to use JSON.stringify method to convert it to JSON string when you send it,. And the model binder will bind the...
Read more >Sending json through api post request - Microsoft Q&A
Sending json through api post request · public string AddItem( JObject jsonString) · { · db.Database.ExecuteSqlCommand("exec zotero.
Read more >JSON:API — Examples
HTTP /1.1 200 OK Content-Type: application/vnd.api+json { "data": [{ "type": ... In the example below, the user is sending an invalid JSON:API request, ......
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 FreeTop 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
Top GitHub Comments
Depending on what you are doing, you need to make sure that the
Accept
header is set too.Axios override default Content-Type
axios.defaults.headers.common['Content-Type'] = 'application/vnd.api+json'
this doesnt work!