cans-plugin-http
HTTP (axios) plugin for cans
Install
$ yarn add cans-plugin-http
Usage
httpPlugin
Example
const app = app app
options
- axiosConfig: AxiosConfig. If provided,
app.http
will returnaxios.create(axiosConfig)
restPlugin
restPlugin
is useful when your backend exposed frontend a standard RESTful interface. restPlugin
will help you generate RESTful cans model that return a observable, which contains RESTful action and loading status:
Method | Path | action |
---|---|---|
GET | /posts | app.models.rest.posts.index |
GET | /posts/:id | app.models.rest.posts.show |
POST | /posts | app.models.rest.posts.create |
PUT | /posts/:id | app.models.rest.posts.update |
DELETE | /posts/:id | app.models.rest.posts.delete |
(Inspired by Egg)
Example
const app = const URL = 'http://jsonplaceholder.typicode.com' app const PostList = <div> posts </div> const PostApp =
options
-
resources
- name: resource name
- url: endpoint URL
- total: (AxiosResponse) => string | number - Compute total count from response
- defaultData: { index: any, show: any } - Data fetched from
rest[name].index
will be set inrest[name].data.index
.show
is the same.index
is[]
by default.show
is{}
by default.
app.models.rest[name]
What in restPlugin create observables for every resource:
observable
License
MIT License