项目作者: davestewart

项目描述 :
Bundle endpoints as callable, reusable services
高级语言: TypeScript
项目地址: git://github.com/davestewart/axios-actions.git
创建时间: 2018-07-09T10:18:06Z
项目社区:https://github.com/davestewart/axios-actions

开源协议:

下载


Axios Actions

Bundle endpoints as callable, reusable services

Abstract

Axios Actions comprises a small set of classes which collate URLs or URL request configs as callable actions.

First, define your endpoints:

  1. const actions = {
  2. <action>: '<url>',
  3. <action>: '<config>',
  4. ...
  5. }

Then, encapsulate them as one of the built-in services:

  1. const service = new <ApiClass>(axios, actions)

Finally, call them:

  1. service
  2. .<action>(<data>)
  3. .then(<handler>)

This service-based approach:

  • removes brittle configuration from components and stores
  • encapsulates additional logic (such as load state and handlers) within the service
  • ensures application code stays simple and semantic
  • provides a dedicated layer for API interaction

There are lots of other goodies in the library which take the drudgery out of working with APIs!

Documentation

Start reading:

Next steps

Demos:

Installation:

  1. npm i -S axios-actions