Get HTML ReadMe
Hi, so this is the first time working with such APIs. Anyway, I was reading on the GitHub API and came across this:
The README supports custom media types to get raw content or rendered HTML.
src: https://developer.github.com/v3/repos/contents/#get-the-readme
What do I believe means it is possible to get the HTML version of the README content? If so, how can I get it using AJAX, since the tutorials are for curling. In the end I want to display part of it on my website and it will be much easier if you specify in html format and not markdown.
The docs say something about: application / vnd.github.VERSION.html
I just don't know how to use it.
Thank!
source to share
You must set the Accept
HTTP request header to application/vnd.github.html
.
$.ajax({
url: 'https://api.github.com/repos/just95/toml.dart/readme',
headers: { 'Accept': 'application/vnd.github.html' }
}).done(function(data) {
alert(data);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
source to share
All you have to do is set Accept
your HTTPS request header . Using cURL like:
curl -i -H "Accept: application/vnd.github.v3.html" https://api.github.com/repos/github/developer.github.com/readme
In JavaScript,
var apiRoot = 'https://api.github.com';
var myUser = YOUR_USER_HERE;
var myRepo = YOUR_REPO_HERE;
var request = new XMLHttpRequest();
request.open('GET', apiRoot + '/repos/' + myUser + '/' + myRepo + '/readme');
request.setRequestHeader('Accept','application/vnd.github.v3.html');
/* add event listeners... */
request.onreadystatechange = function() {
if (request.readyState === 4 && request.status === 200) {
document.body.innerHTML = request.response;
}
};
request.send();
source to share