redux-json-api provides a simple API for all four CRUD actions.
- Create resource object using createEntity
- Read endpoints through readEndpoint
- Update resource with updateEntity
- Delete resource using deleteEntity
Whenever there's referred to a resource object or entity, it must conform to JSON API specifications.
redux-json-api resolves resource objects to endpoints based on their specified type. The following resource will update and delete to /tasks/1:
{
"id": 1,
"type": "tasks",
"attributes": {
"title": "Lorem ipsum"
}
}
While dispatching a create action for the following resource will make a request to /tasks:
{
"type": "tasks",
"attributes": {
"title": "Lorem ipsum"
}
}
The redux-json-api's CRUD API methods will all return a single promise. The fulfillment handler will receive one argument with the response body. One exception to this is the fulfillment handler from a deleteEntity
promise, which will not receive any arguments.
Note: Return values noted below are after dispatch, i.e. dispatch(createEntity({ ... }))
.
Use this action creator to trigger a POST request to your API with the given resource.
This action creator will trigger a GET request to the specified endpoint.
Update entities using this action creator. It will make a PATCH request to your API.
Use this action creator to issue a DELETE request to your API.