Creates api
instance object, with the same structure as given spec
.
spec
: Spec - Api definition.queryConfig
: QueryConfig - Api request configuration, could be ovverrided in spec entry.settings?
: Settings - Api settings.
Returns: Api
Creates middleware for listening request actions and fetching data from server. Accepts multiple api instances.
api
: Api - Api instance object.
Returns: Redux middleware function.
Creates reducer for given api instance. Should be mounted at state.api
path unless selector
option is specified at Settings.
api
: Api - Api instance object.
Returns: Redux reducer.
Api spec object. Could have any level of nesting. Contains SpecEntry objects as values.
Api spec entry object. Contains description of api request.
path
: string - Url path of api call. Accepts params in format:[param_name]
.method
: string - Http method of request.config?
: QueryConfig - Request configuration. Overrides default config.
Api request configuration.
endpoint
: string - Api endpoint.
Api instance settings.
context?
: string =""
- Prefix, which will be added in the beginning of action types in the specific api.selector?
: function =(state) => state.api
- Selector, returning api reducer.
Api instance object. Contains ApiEntry objects as values. Has the same structure as it's Spec.
Api entry object. Contains all needed data for making and handling api request.
select
: ApiEntry.select - Returns redux selector according givenkey
.type
: ApiEntry.type - Returns action type according givenkey
.actions
: Actions - Object of redux action creators.reducer
: ApiEntry.reducer - Api entry reducer. Used internally in the library and in the enhancer API.fetch
: ApiEntry.fetch - Function, used to making api requests. Used internally in the library and in the enhancer API.
key
: 'data' | 'isFetching' | 'lastUpdated' | 'error' - Api entry state key.
key
: 'request' | 'success' | 'failure' - Action typekey
.
state
: State - Api entry state object.action
: Object - Redux action.
onSuccess
: function - Callback, which will be called when request succeeded.onFailure
: function - Callback, which will be called when request failed.payload?
: RequestAction.payload - Request action payload object.
Async actions creators object.
request
: Actions.request - Request action creator function.success
: Actions.success - Success action creator function.request
: Actions.failure - Failure action creator function.
payload?
: RequestAction.payload - Request action payload data.
payload
: SuccessAction.payload - Success action payload data.
payload
: FailureAction.payload -Failure action payload data.
Request action object.
type
: string - Action type, has format like "[prefix/[path]/request]".payload?
: RequestAction.payload - Request action payload data.
params?
: Object - Params of api request, should correspond to params, defined in SpecEntrypath
.body?
: any - Request body data.
Success action object.
type
: string - Action type, has format like "[prefix/[path]/success]".payload?
: SuccessAction.payload - Success action payload data.
meta
: ResponseMeta - Object, containing meta data of response.request?
: RequestAction.payload - Payload of request action.body?
: any - Response body data.
Failure action object.
type
: string - Action type, has format like "[prefix/[path]/failure]".payload?
: FailureAction.payload - Failure action payload data.
meta
: ResponseMeta - Object, containing meta data of response.message
: string - Error message.request?
: RequestAction.payload - Payload of request action.body?
: any - Response body data.
Meta data of response.
status
: number - Response status code.receivedAt
: number - Response timestamp.
Api entry state object.
isFetching
: boolean - Value, determining whether data is fetching from server or not.request?
: RequestAction.payload - Payload of request action.data?
: any - Response body data.lastUpdated?
: number - Timestamp of last request.error?
: string - Error message.