JSPM

simple-reddit-api

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q43099F
  • License ISC

A simple reddit api that doesnt require auth.

Package Exports

  • simple-reddit-api

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-reddit-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

simple-reddit-api

Simple client for the reddit public api. (No auth needed)

Get it from npm

npm i simple-reddit --save

Import

const Reddit = require("simple-reddit");

or just import individual functions.

const {topPost} = require("simple-reddit");

Usage

Basic examples:

Get top post from reddit.

RedditSimple.topPost(options).then(res => {
    console.log(res);
})

 

Get new post from reddit.

RedditSimple.newPost(options).then(res => {
    console.log(res);
})

 

Get random post from reddit.

RedditSimple.randomPost(options).then(res => {
    console.log(res);
})

 

Search if a subreddit exists.

RedditSimple.searchSubreddits('dankmemes').then(res => {
    console.log(res);
})
  • Args: Name of subreddit to be searched. (Required)

 

RedditSimple.popularSubreddits(count).then(res => {
    console.log(res);
})
  • Args: Number of subreddits to be displayed. (Defaults to 1)

Options

There are 4 options that you can pass.

Name Value Description Default
subreddit name of subreddit Subreddit to fetch the post. r/all
count Number of posts to retrieve Retrieves n number of posts. 1 (max:100)
is_meme true/false If you want to get a meme. Ignores subreddit option if true. false
fulldata true/false Retrieve essential post data or everything reddit has to offer. false
#

Values returned from the method

Post details

{
    status:200/404, //404 if any error occurs
    posts:[ //empty incase of error/no subreddit
        {
            data: {
                title: string,
                author: string,
                subreddit_name_prefixed: string,
                ups: number,
                total_awards_received: number,
                url: string,
            }
        } //Incase of fulldata:true, posts array has the raw post object returned by reddit
    ]
}

Search subreddits

{
    status: 200/404, //404 if any error occurs
    subreddit: subreddit,
    url: `${api}${subreddit}`
}

List subreddits

{
    status:200/400, //404 if any error occurs
    subreddits:[  //array empty in case of error
        {
            data: {
                display_name_prefixed: string,
                subscribers: string,
                description: string,
                url: string
            }
        }
    ]
}