cataas-api
v1.1.2
Published
Cat as a service API wrapper for javascirpt
Downloads
7
Maintainers
Readme
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
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
beforeget()
|download()