JSFiddle - React, Tailwind, and code Playground
HTML
We pull the medium posts using this Clay service:
<a href='https://clay.run/services/nicoslepicos/medium-get-user-posts-simple'>
https://clay.run/services/nicoslepicos/medium-get-user-posts-simple
</a>
<div id='recent-medium-posts'>
</div>
JavaScript
// Sending and receiving data in JSON format using POST mothod
xhr = new XMLHttpRequest();
let url = "https://exec.clay.run/nicoslepicos/medium-get-user-posts-new/";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
let returned = JSON.parse(xhr.responseText);
// the posts should be stored in returned.posts, which is an object, so we need to loop through the properties in the object, which are the posts
let postsObject = returned.posts
for (var key in postsObject) {
// skip loop if the property is from prototype
if (!postsObject.hasOwnProperty(key)) continue;
let post = postsObject[key];
console.log(post);
document.getElementById('recent-medium-posts').innerHTML += "<div><h2>"+ post.title +"</h2>" + post.title + "</div>";
}
}
}
let data = JSON.stringify({"profile":"nicolaerusan"});
xhr.send(data);