Code Monkey home page Code Monkey logo

allapis's Introduction

allapis

In case you want to simplify the apis and create instances

  • Fast
  • Simple
  • Light

Example

// Import the Api
import Api from 'allapis'

// Create Api object
const pokeApi = Api('https://pokeapi.co/api/v2/') // eg. pokeapi

// Its ready to use
const ditto = await pokeApi.pokemon.ditto.get().then(r => r.json())
console.log(ditto)

// you can save routes
const berries = pokeApi.berry
const cheri = berries['1'].get().then(r => r.json())
console.log(cheri)

// predenfine fetch options
const discordApi = Api({
    url: 'https://discord.com/api/v10',
    headers: {
        Authorization: `Bot ${process.env.DISCORD_TOKEN}`,
        'Content-Type': 'application/json'
    }
})
const channel = discordApi.channels['885674115615301643']

// use url query like a string
const messages1 = await channel.messages.get('limit=20').then(r => r.json())
// or like a object
const messages2 = await channel.messages
    .get({
        query: {
            limit: 50,
            around: messageId
        }
    })
    .then(r => r.json())

// use post, delete, put, patch methods too
channel.messages
    .post({
        body: JSON.stringify({
            content: 'hello!!'
        })
    })
    .catch(console.error)

Requeriments

You need to have Node ^18

Or have Node ^17.5 and run your program with the --experimental-fetch flag

Or have Node ^16.15 and run your program with the --experimental-fetch flag

Or if you use another version of Node you should install node fetch with npm i node-fetch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.