Joke API Client for NodeJS
A Node.js wrapper for the JokeAPI with only one dependency.
• Installation
npm i @qgisk/jokeapi-wrapper
• JokeAPI Documentation
For complete API documentation, up-to-date parameters, responses and errors, please refer to JokeAPI
• Constants
This module provides helper constants for use in calls.
Key | Usage | Description |
---|
BASE | JokeAPI.BASE | Base url for api |
HOST | JokeAPI.HOST | Host url |
API_VERSION | JokeAPI.API_VERSION | Current api version |
CATEGORIES | JokeAPI.CATEGORIES | Lists all avaliable categories |
BLACKLIST_FLAGS | JokeAPI.BLACKLIST_FLAGS | Lists all avaliable blacklist flags |
FORMAT | JokeAPI.FORMAT | Lists all avaliable formats |
TYPE | JokeAPI.TYPE | Lists all avaliable types |
AMOUNT_MAX | JokeAPI.AMOUNT_MAX | Max amount of jokes per request |
• Quick Start Example
const JokeAPI = require('@qgisk/jokeapi-wrapper');
const JokeClient = new JokeAPI();
const get = async () => {
const joke = await JokeClient.getJoke();
console.log(joke);
};
get();
• With Options
Key | Type |
---|
apiKey | string |
safemode | boolean |
format | string |
blacklistFlags | string/array |
lang | string |
• Example
const JokeClient = new JokeAPI({ apiKey: 'exampleapikey', safemode: true, format: 'xml' blacklistflags: ['nsfw'], lang: 'de'});
• Categories & BlacklistFlags
can be given in an array or a string seperated by ,
• Example
const JokeClient = new JokeAPI({ blacklistflags: ['nsfw', 'explicit'] });
const joke = await JokeClient.getJoke({ categories: 'coding,dark' });
• Get Joke
Key | Type |
---|
categories | string/array |
format | string |
blacklistFlags | string/array |
lang | string |
idRange | number |
contains | string |
type | string |
amount | number |
• Example
const joke = await JokeClient.getJoke({ categories: ['Coding', 'dark'] });
or
const joke = await JokeClient.getJoke({ categories: 'Coding,dark' });
or
const joke = await JokeClient.getJoke();
• Info
Key | Type |
---|
format | string |
lang | string |
• Example
const info = await JokeClient.info();
or
const info = await JokeClient.info({ format: 'text', lang: 'en' });
• Categories
Key | Type |
---|
format | string |
lang | string |
• Example
const categories = await JokeClient.categories();
or
const categories = await JokeClient.categories({ format: 'text', lang: 'en' });
• Langcode
Key | Type |
---|
format | string |
language | string |
• Example
const langcode = await JokeClient.langcode();
or
const langcode = await JokeClient.langcode({ format: 'text', language: 'english' });
• Languages
Key | Type |
---|
format | string |
lang | string |
• Example
const languages = await JokeClient.languages();
or
const languages = await JokeClient.languages({ format: 'text', lang: 'en' });
• Flags
Key | Type |
---|
format | string |
lang | string |
• Example
const flags = await JokeClient.flags();
or
const flags = await JokeClient.flags({ format: 'text', lang: 'en' });
• Formats
Key | Type |
---|
format | string |
lang | string |
• Example
const formats = await JokeClient.formats();
or
const formats = await JokeClient.formats({ format: 'text', lang: 'en' });
• Ping
Key | Type |
---|
format | string |
lang | string |
• Example
const ping = await JokeClient.ping();
or
const ping = await JokeClient.ping({ format: 'text', lang: 'en' });
• Submitting
For testing define dry-run as anything
• Example
const submitSingle = await JokeClient.submit({
'dry-run': true,
formatVersion: 3,
category: 'Misc',
type: 'single',
joke: 'testing',
flags: { nsfw: true, religious: false, political: false, racist: false, sexist: false, explicit: true },
lang: 'en',
});
const submitDouble = await JokeClient.submit({
'dry-run': true,
formatVersion: 3,
category: 'misc',
type: 'twopart',
setup: 'Setup',
delivery: 'Delivering',
flags: { nsfw: true, religious: false, political: false, racist: false, sexist: false, explicit: true },
lang: 'en',
});
• Inspiration
miscavage
• License
MIT