RASCL then tracks the "lifecycle" of each API call as a finite state machine. As the API call "moves" through the lifecycle, each stage dispatches a Redux action containing the relevant data.
An API endpoint's state transitions
-
INITIAL - This is the starting state for all endpoints. An endpoint at
INITIALhas not been used. No API calls have been made, no actions have been dispatched, and all data fields will still benull.
-
ENQUEUE(Optional) - The optional
ENQUEUEstate allows for common utility patterns. An "offline-first" webapp may want to allow enqueueing multiple requests while offline, or a modal login window may be rendered over the application, which has UI logic that makes API calls as soon as possible after rendering. In either case,ENQUEUEallows a developer to create preconditions for certain calls, for instance to say "only make this call once the device is online and the user has valid credentials". -
REQUEST - An endpoint is set to the
REQUESTstate after the API request has been made, but before any response has come back. This will setisFetchingtrue`, which is useful for triggering spinners or blocking user actions while awaiting data.
-
FAILURE - Usually indicates a
4XXresponse from the API. -
MISTAKE - Indicates a
5XXresponse from the API.