All Projects → Fl0pZz → Apipie

Fl0pZz / Apipie

Licence: mit
Transform api declaration to js object for frontend. Inspired by VueRouter, koa-middleware and axios.

Programming Languages

javascript
184084 projects - #8 most used programming language
declarative
70 projects

Projects that are alternatives of or similar to Apipie

Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+36568.97%)
Mutual labels:  api, rest, api-client, rest-client
Binance
A .NET Standard Binance API library.
Stars: ✭ 199 (+586.21%)
Mutual labels:  api, api-client, api-wrapper
Slack
🎉✨ Slack API client for Node and browsers.
Stars: ✭ 903 (+3013.79%)
Mutual labels:  api, api-client, api-wrapper
Pizzly
The simplest, fastest way to integrate your app with an OAuth API 😋
Stars: ✭ 796 (+2644.83%)
Mutual labels:  api, api-client, api-wrapper
Js Client
A Open-API derived JS + Node.js API client for Netlify
Stars: ✭ 170 (+486.21%)
Mutual labels:  api, rest, api-client
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (+524.14%)
Mutual labels:  api, rest, api-wrapper
Yet Another Rest Client
YARC (Yet Another REST Client) is an easy-to-use REST Client for Google Chrome.
Stars: ✭ 23 (-20.69%)
Mutual labels:  api, rest, rest-client
Anyapi
AnyAPI is a library that helps you to write any API wrappers with ease and in pythonic way.
Stars: ✭ 126 (+334.48%)
Mutual labels:  api, api-client, api-wrapper
Azure Devops Python Api
Azure DevOps Python API
Stars: ✭ 257 (+786.21%)
Mutual labels:  api, rest, rest-client
Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (+841.38%)
Mutual labels:  api, rest, rest-client
Hubspot Php
HubSpot PHP API Client
Stars: ✭ 273 (+841.38%)
Mutual labels:  api, api-client, api-wrapper
Coingecko Api
A Node.js wrapper for the CoinGecko API with no dependencies.
Stars: ✭ 159 (+448.28%)
Mutual labels:  api, api-client, api-wrapper
Mobx Rest
REST conventions for Mobx
Stars: ✭ 164 (+465.52%)
Mutual labels:  api, rest, api-client
Virustotal Api
Virus Total Public/Private/Intel API
Stars: ✭ 189 (+551.72%)
Mutual labels:  api, api-client, api-wrapper
Jda
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Stars: ✭ 2,598 (+8858.62%)
Mutual labels:  api, rest, api-wrapper
Httpie
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie
Stars: ✭ 53,052 (+182837.93%)
Mutual labels:  api, rest, api-client
Api Php Client
PHP client of Akeneo PIM API
Stars: ✭ 56 (+93.1%)
Mutual labels:  api, rest, api-client
Datafire
A framework for building integrations and APIs
Stars: ✭ 487 (+1579.31%)
Mutual labels:  api, api-client, rest-client
radiobrowser4j
RadioBrowser Java API library
Stars: ✭ 30 (+3.45%)
Mutual labels:  api-client, api-wrapper, rest-client
Vuex Rest Api
A utility to simplify the use of REST APIs with Vuex
Stars: ✭ 365 (+1158.62%)
Mutual labels:  api, rest, axios

Apipie

Утилита для построения из декларативно описанного дерева REST API endpoint's в слой api в виде объекта с функциями.

Проект вдохновлен VueRouter, koa2 и axios.

Использует для обработки путей path-to-regexp и для отправки http запросов axios

Установка

# Через yarn:
yarn add apipie
# Через npm:
npm install apipie

С помощью CDN

<script src="https://unpkg.com/apipie"></script>

Документация

Для [email protected] - https://fl0pzz.gitbooks.io/apipie-docs/content/

Для более старых версий - https://github.com/Fl0pZz/Apipie/tree/old_v0.14 (которую вы скорее всего используете!)

Пример

Api.js

import createApi from 'apipie'
import axios from 'axios'

const hook = async (ctx, next) => {
  console.log(`I'm hook!`)
  await next()
}

const data = true
const query = true

const resources = [
  {
    name: 'user', // Далее это будет использоваться для отправки запроса
    options: { ... }, // Все опции можно найти https://github.com/mzabriskie/axios#request-config
    get: '/user/:id', // Сахар который будет преобразован в { url: '/user/:id', method: 'get' }
  },
  {
    name: 'settings',
    url: '/settings',
    method: 'get',
    children: [
      { 
        name: 'setStatus', 
        post: '/set_status',
        query // Если query = true, то передача query параметров для этого ресурса будут обязательными.
      },
      { name: 'changeAvatar',
        url: '/change_avatar',
        method: 'post'
      }
    ]
  }
]

/**
* Все глобальные настройки для axios можно определить заранее.
* Есть возможность прокидывать глобальные хуки, которые выполняют перед запросом в axios.
*/

const api = createApi(resources, axios, { hooks: [ hook ] })

export default api

Somefile.js

import api from './api'

api.user() // Выкинет ошибку, так как :id обязательный параметр. За подробностями https://github.com/pillarjs/path-to-regexp

api.user({ params: { id: 1 } }) // GET: /user/1
  .then(ctx => { console.log(ctx.response) }) // Схему для response, можно посмотреть тут https://github.com/mzabriskie/axios#response-schema
// Схему для объекта ctx смотрите в документации дальше.


api.settings() // GET: /settings

api.settings.setStatus() // Ошибка, нужно передать query объект.

// POST: /set_status?status=my_status
api.settings.setStatus({ query: { status: 'my_status' } })
  .then({ response } => { console.log(response) })


const avatar = document.querySelector('img').src

api.settings.changeAvatar({ data: { avatar } }) // Так же можно передать FormData, https://github.com/mzabriskie/axios#request-config
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].