Skip to content

Cat as a service API wrapper for Javascript and Typescript.

License

Notifications You must be signed in to change notification settings

iArmanKarimi/Cataas-API-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cataas API

Cat as a service API wrapper for Javascript and Typescript.

Cat as a service is a REST API to spread peace and love (or not) thanks to cats.

Install

npm install --save cataas-api

Tip: If you only need the url, refer to url-encoder branch.

Examples

constructor()

var Cataas = require('cataas-api')
var cataas = new Cataas()
var gif = {
    Gif: true,
    Size: 'md',
    Text: "hey dude",
    Filter: "paint",
    TextSize: 35,
    TextColor: "LightBlue",
}
var resized = {
    Width: 300,
    Height: 200,
}
cataas.options = gif
cataas.options = resized

encode()

var encodedUrl = cataas.encode()

encodeById(id)

var encodedUrl = cataas.encodeById('[ID]')

async get()

cataas.encode()
cataas.get()
    .then(readable => {
        const stream = new fs.createWriteStream('cat.png')
        readable.pipe(stream)
    })
    .catch(e => console.error(e))

async download(path)

cataas.encode()
cataas.download('cat.png')
    .then(successful => {
        if (successful) {
            console.log('Downloaded file successfully')
        }
    })
    .catch(e => console.error(e))

async getAllTags()

cataas.encode()
cataas.getAllTags()
    .then(tags => {
        console.log('Tags length:', tags.length)
    })
    .catch(e => console.error(e))

async getCats(tags, options)

cataas.encode()
cataas.getCats(['cute'])
    .then(cats => console.log('Results length:', cats.length))
    .catch(e => console.error(e))

Typescript example

import Cataas from 'cataas-api';

const cataas = new Cataas()
cataas.encode()
cataas.getCats(['cute'], { Limit: 5 })
    .then(cats => {
        cats.forEach(cat => {
            console.log(`${cat.id}: ${cat.tags}`))
        }
    })
    .catch(e => console.error(e))

Tips

  • After setting Gif: true in options, Tag is ignored
  • Don't forget to encode() | encodeById before get() | download()

Reference

API website

License

MIT