Reputation: 711
I'm using javascript's XMLHttpRequest to receive data from Github API and I am trying to use the custom media type specification but can't get it to work. Setting the Accept
header doesn't change the format of the response at all. The result I get is always the default (JSON).
This is the code I'm using to make the request:
var url = "https://api.github.com/repos/mrdoob/three.js/issues/comments/241553390";
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.setRequestHeader("Accept", "application/vnd.github.v3.raw");
xhr.setRequestHeader("Content-Type","application/vnd.github.v3.raw");
xhr.onload = function(ev) {
console.log("Response:", ev.target.response);
console.log("Headers:", xhr.getAllResponseHeaders());
};
xhr.send();
Upvotes: 0
Views: 379
Reputation: 174
The response JSON contains a "body" attribute.
I tried changing the version from raw to other types and noticed that only the "body" attribute changes. Did I understand your question wrong? What other types of response does GitHub API support?
xhr.setRequestHeader("Accept", "application/vnd.github.v3.html");
results in "body_html"
while xhr.setRequestHeader("Accept", "application/vnd.github.v3.html");
results in "body"
JSFiddle here - https://jsfiddle.net/3yqutj29/4/
Upvotes: 1
Reputation: 6923
You are requesting comments, which are all returned as JSON which you can use the media type to specify the body markdown. See: https://developer.github.com/v3/media/#comment-body-properties
The application/vnd.github.v3.raw
is used for requesting a binary blob.
Upvotes: 0