Skip to content

Latest commit

 

History

History
71 lines (45 loc) · 2.08 KB

api.md

File metadata and controls

71 lines (45 loc) · 2.08 KB

API

redux-json-api provides a simple API for all four CRUD actions.

Resource objects

Whenever there's referred to a resource object or entity, it must conform to JSON API specifications.

Resource endpoints

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"
  }
}

API Promises

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.

API Methods

Note: Return values noted below are after dispatch, i.e. dispatch(createEntity({ ... })).

createEntity( resource: object ): Promise

Use this action creator to trigger a POST request to your API with the given resource.

Examples and details here.

readEndpoint( endpoint: string ): Promise

This action creator will trigger a GET request to the specified endpoint.

Read more.

updateEntity( resource: object ): Promise

Update entities using this action creator. It will make a PATCH request to your API.

Details and examples.

deleteEntity( resource: object ): Promise

Use this action creator to issue a DELETE request to your API.

More details on deleteEntity