Conventions for API Request Actions

The following convention/pattern is how I manage my loading and error logic for API requests.

Any action type that starts with REQUEST_ is a starting action:

SomeAction.REQUEST_SOMETHING

Then if any action type that starts with a REQUEST_ and ends with _FINISHED is a finished action:

SomeAction.REQUEST_SOMETHING_FINISHED

This way you can create logic to determine if the loading state is either true or false for an action. I am using the Flux Standard Action pattern and with that pattern there is an error property where it can be set to true or false . This allows us to show or remove an error message when the action has finished or restarted. Below is an example of Flux Standard Action pattern for an action:

Flux Standard Action Example

With this pattern an action MUST NOT include properties other than type , payload , error , and meta so all your actions are consistent and predictable.

Before I show you the code for making this all work let’s go over how to show errors in the same view.