Even faster React/Redux development
npm i --save koiki
Parameter | Type | Meaning | Place to specify | Remark |
---|---|---|---|---|
urls | Object | Resource URLs | client / server | |
reducers | Object | Reducers | client / server | |
routes | Object | Routes | client / server | |
isDevelopment | Boolean | Development Flag (For debug) | client / server | |
manifest | Object | Extend manifest.json setting | server | |
app | Object | Instance of express | server | |
path | String | Root URI | server | |
origin | String | Origin URL | server | |
i18ndir | String | i18n properties directory path | server | |
handlers | Object | - | server | |
handlers.error | Function | Error callback | server |
import { passporter } from 'koiki';
import express from 'express';
const app = express();
passporter.use({
github: {
appId: 'PLEASE SET GITHUB API CLIENT ID',
secret: 'PLEASE SET GITHUB API SECRET ID',
}
}, app, originUrl);
{
person: {
gets: {
method: 'GET',
url: 'https://chaus.herokuapp.com/apis/koiki/people'
},
create: {
method: 'POST',
url: 'https://chaus.herokuapp.com/apis/koiki/people'
}
}
}
First layer property will be use as of person
resource.
Second layer property will be use as of gets
action. ( action name will be captalized )
fetcher.person.gets
from asyncConnect or containers context.Then result will be call with actions below.
Example below.
fetcher.person.gets({
age: 25
});
fetcher will be response Promise object. So you can do like this.
fetcher.person.save({
name: 'foo'
age: 25
}).then(
() => fetcher.person.gets()
);
Responsed object can get from action.body. action.res has Fetch API's responsed object.
export default function reducer(state = initialState, action = {}) {
...
case GETS_SUCCESS:
return {
...state,
loading: false,
loaded: true,
items: action.body.items
};
...
You can write after / override / next properties under urls object to customize fetcher logic.
When resource has hypermedia link, we can call fetcher.person.gets.next()
to get next items.
{
person: {
gets: {
method: 'GET',
url: 'https://chaus.herokuapp.com/apis/koiki/people',
/* If API response next paging resource such as
* {
* paging: {
* next: 'https://....'
* }
* }
*/
next: action => action.body.paging.next
},
},
...
}
fetcher.person.gets.next
after called fetcher.person.gets
on containers.v6.0.0
v5.0.0
See below to know example https://github.com/sideroad/floras/commit/68ee25cccdc94cc5bbb544d7f6e99842a6ff3300 https://github.com/sideroad/corkpin/commit/e5eeb7f46d6382dd27ce5622c2a60e0a01bc3194
v4.0.0
then
callback only get response JSON object.after
callback only get response JSON object.then
callback gets { body: response JSON object, res: fetch response object }after
callback gets { body: response JSON object, res: fetch response object }