Giter Site home page Giter Site logo

medium-json-feed's Introduction

Medium JSON Feed

Get Medium latest articles in JSON format

Medium's public API is quite limited and it is not possible to fetch data from browsers due to CORS issue. Use this package in your server to get JSON article list from Medium or fork and deploy this minimum server to Heroku or another PaaS.

Installation

npm install medium-json-feed --save

Usage

Gets the user/publication name and an optional callback or stream. Returns a promise.

mediumJSONFeed(endpoint: string, callback?: Function | Stream): Promise

Simple example:

const mediumJSONFeed = require('medium-json-feed');

// Usernames start with '@'
mediumJSONFeed('@my-user-name')
  .then(data => ...)
  .catch(data => ...);

// Publication names without '@'
mediumJSONFeed('my-publication-name', data => ...);

// Medium's top page (trending posts)
mediumJSONFeed().then(data => ...);

Other endpoint examples are @user-name/latest, publication-name/latest or publication-name/trending.

The data response contains:

  • data.status: HTTP status code (number).
  • data.error: Error message if exists (string).
  • data.response: List of found articles (Array). The format is the one returned by Medium. Inspect data.response[...].content and data.response[...].virtuals for useful information.

To get the full raw response given by Medium, provide a stream:

// Raw stream pipe to stdout
mediumJSONFeed('@my-user-name', process.stdout);

// Raw stream pipe to server's response
mediumJSONFeed('@my-user-name', response);

Note: the raw output will likely contain random chacters at the beginning of the string that break JSON format.

For a full example, see server.js file.

Live demo (hopefully)

See The Web Tub's trending articles or Mikeal Roger's latest articles.

Deploying to Heroku

  1. Clone this repo.
  2. Create a new app in your Heroku account.
  3. Choose GitHub deploy and select your fork.
  4. Set environment variables PORT and ORIGIN (for Access-Control-Allow-Origin header).
  5. Hit 'deploy'.

medium-json-feed's People

Contributors

frandiox avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.