imageapi.js

The best way to get random posts from subreddits


Keywords
image, api, js, custom, reddit, async, reddit-api, imageapi
License
MIT
Install
npm install imageapi.js@1.7.0

Documentation

ImageAPI.JS

npm stars contributors

What?

ImageAPI is a wrapper for ImageAPI.fionn.live - a fast API for fetching a random post from a subreddit.

How?

The main API is just fetching random data from the reddit API allowing for us to send the data we think is valid back to the user making the request.

Is it fast?

The API is as fast as the Reddit API is. We can't speed it up, but, we have optimized the code on the backend to make it as fast as possible.

Examples:

✌ JS example
const api = require('imageapi.js');
(async () => {
	const img = await api('subreddit');
	console.log(img); // Logs the image
	const advanced = await api.advanced('subreddit');
	console.log(advanced); // Logs an object. Not all data may be present.
	const stats = await api.stats();
	console.log(stats); // Logs an object.
})();
😎 TS example
import api, { stats, advanced } from 'imageapi';
(async () => {
	const img = await api('subreddit');
	console.log(img); // Logs the image
	const advanced = await api.advanced('subreddit');
	console.log(advanced); // Logs an object. Not all data may be present.
	const stats = await api.stats();
	console.log(stats); // Logs an object.
})();

Sort types, top & new.

If you want to get a 'new' or 'top' post, you can specify a sort type. The valid ones are top & new.

You specify this as a second paramter in the advanced & default function. For example:

api.advanced('meme', 'top'); // Gets a 'top' meme
api.advanced('meme', 'new'); // Gets a 'new' meme
api.advanced('meme', 'this-is-invalid'); // Errors, returns a rejected promise