Skip to content

Latest commit

 

History

History
79 lines (50 loc) · 2.52 KB

api.md

File metadata and controls

79 lines (50 loc) · 2.52 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 deleteResource promise, which will not receive any arguments.

API Methods

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

createResource( resource: JsonApiResource ): Promise<JsonApiDocument>

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

Examples and details here.

readEndpoint( endpoint: string ): Promise<JsonApiDocument>

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

Read more.

updateResource( resource: JsonApiResource ): Promise<JsonApiDocument>

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

Details and examples.

deleteResource( resource: JsonApiResource ): Promise<void>

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

More details on deleteResource

hydrateStore( payload: JsonApiDocument ): Action

Use this action to hydrate the store with e.g. bootstrapped data.

More details on hydrateStore