I once had an anonymous blog

Just over eleven years ago, I started my first real world job as an intern at an architecture firm in NYC. I had a few friends that worked at this firm, and on a whim I decided to apply for a job…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to get your Medium posts on your website

Get your Medium posts to your website via Medium APIs

A brief tutorial on how to display your latest posts on your website.

Some months ago I got the idea to add a blog section to my portfolio: an area where I could share my experiences and learnings. The idea was amazing: create a custom small CMS with Node.js, maybe linked to a MongoDB database. I’d have also to create a CMS interface, handle the post status and several other things. Although the idea was feasible, it would have also required quite a bit of time to develop and test the code.

At that point I asked myself, why not to use an existing platform? Take Medium, for example: awesome editor, great minimal UI and a cheerful and rich community of users. And so I did choose Medium as media to post and display my, lets say it, mediocre posts.

Sniffing around google and Stack Overflow I found some guys saying that answer lied in their rss feed: https://medium.com/feed/@username

Client side issues! So, let’s focus on how I solve the issue.

As we said, I faced these errors because I was trying to get this ajax call from the client. Lets bypass the issue and fetch my posts from the server.

On my Node server, managed by express.js, I first had to create a new controller and refer it to its core file. The chosen route is /get-posts, so once the controller is setup I can access oldirony.cc/get-posts via GET to receive a json object with my Medium posts.

In get-posts.js, the first thing you’ve to do is to export as default the controller function:

At this point, we have to make the actual GET request. I used axios as library to fetch the posts, as I already had it in my dependencies.

On call success, I send the stringified version of the response data to the page.

Yes, It’s not finished yet. I found on the internet people suggesting to append ?format=json to the endpoint url to get the data in a JSON format, but, I don't know why, it didn't work for me.

So, as the documentation is almost inexistent, I chose another solution.

Using the xml2js library, I parsed the string using its own function parseString and I sent back to the page the stringified list of articles res2.rss.channel[0].item .

Now that we got our list of posts of our Node server we can easily access them from our page.

I’m using React and Redux on portfolio, so what I did was to setup an action creator that fetches from our predefined route ‘/get-posts’ on a specific homepage section onMount event.

This, anyway, is the essential code:

Originally published at https://medium.com on October 1, 2017.

Add a comment

Related posts:

Protecting Our Digital Environment

Just as we depend on the climate and biosphere that surround us, we’ve been enveloped by an array of digital services — spaces where we work, entertain ourselves, gather information, and where…

Zokyo and Buidl Capital Partner with Struct Finance

Zokyo and Buidl Capital are partnering with Struct Finance, the first permissionless protocol to offer structured products in the Decentralized Finance (DeFi) space. Struct recently closed a $3.5…

How a Centralized System for 6 Regions and 9 Brands Is Helping a Global Market Leader

Every success story about our customers who implemented the Pimcore Platform to solve their business challenges is a story that adds a unique perspective to our portfolio. There are several reasons…