needle
needle copied to clipboard
How to send a json representation of the data but with custom Accept header?
I am doing a post to Github API which requires custom Accept header and json representation. This is what I have
var options = {
headers: {
Authorization: 'token <token>',
Accept: 'application/vnd.github.everest-preview+json'
},
}
var data = {
event_type: "autotest",
client_payload: {"componentToRun": "app"}
}
try {
const res = await needle("post", 'https://api.github.com/repos/myrepo/reponame/dispatches',
data, options);
} catch(e) {
}
If I set json: true
in options, the accept header is changed to Application/Json which is not what I want. I simply want to send the data as json without it touching my headers.
In that case don't pass json: true
and pass JSON.stringify(data)
instead of data
.