![Commitizen friendly](https://camo.githubusercontent.com/1d01d79de532fa2a8b9d3e1c29e2b5d6f700b6d36f108c8416faca472cb35b6f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6d6d6974697a656e2d667269656e646c792d627269676874677265656e2e737667)
// recrud.config.js
import { configure } from 'recrud'
import { crudRequest } from 'recrud/saga'
export default configure({
baseUrl: 'https://example.com/api',
crudRequest
})
Root/non-nested resources
// components/Team/service.js
import recrud from './recrud.cofig.js'
export const crud = recrud.makeCrud({
resource: 'users',
actionPrefix: 'USER'
})
// components/Team/sagas.js
yield fork(crud.request.fetchList)
// components/TeamPlayer/service.js
export const crud = recrud.makeCrud({
resource: ({ partitionKeyValue }) => `teams/${partitionKeyValue}/players`,
key: 'name',
actionPrefix: 'TEAM_PLAYER'
})
// components/TeamPlayer/sagas.js
yield fork(crud.request.fetchList, {
partitionKeyValue: teamName
})
Complex/deeply-nested resources
// components/TeamPlayerGame/service.js
export const crud = recrud.makeCrud({
resource: ({ teamName, playerId }) => `teams/${teamName}/players/${playerId}/games`,
key: 'id',
actionPrefix: 'TEAM_PLAYER_GAME',
responseCollectionKey: 'teamPlayerGames',
defaultRequestParameters: {
prefix: '/complex/'
}
})
// components/TeamPlayerGame/sagas.js
yield fork(crud.request.fetchList, {
partitionKeyValue: `${teamName}:${playerId}`,
resourceArgs: { teamName, playerId }
})
export const crud = recrud.makeCrud({
resource: ({ partitionKeyValue }) => `teams/${partitionKeyValue}/players`,
key: 'name',
actionPrefix: 'TEAM_PLAYER'
})
crud.request.search = crud.makeRequestor({
type: 'fetchList',
service: crud.serviceFactory({ resource: 'players' })
})