Names
Request names are a feature that can be useful if you are automatically generating request keys. If you are not automatically generating request keys, then you probably do not need to use request names.

Motivation

Automatically-generated request keys are useful for advanced networking features such as response caching and request deduplication, but they are often an inconvenience when it comes to debugging code.
For instance, if you have an endpoint that allows a user to run a search, two searches against the endpoint may have the keys "aBui9Xc" and "9d8cdd3". These keys don't communicate the purpose of these requests; they are just arbitrary strings.
Providing a request name can help developers who are debugging the application. In that situation, a request name like "searchBooks" could be specified. Later, when a developer is looking at the request, they will have some context on what the intention of the request is.
Request names are like function names in JavaScript. Although we could use anonymous functions everywhere, we tend to provide names for our functions so that developers know what they do.
In summary, request names are optional, human-readable descriptions of what the request's intention is.

Specifying a Request Name

Add the requestName property to a request action to specify a name for that request.
1
import { actionTypes } fom 'redux-resource';
2
import store from './store';
3
4
store.dispatch({
5
type: actionTypes.READ_RESOURCES_PENDING,
6
resourceType: 'books',
7
8
// In this situation, we are generating a key. It could be a random string of data,
9
// which makes debugging hard.
10
requestKey: generateRequestKey(/* request data */),
11
12
// By specifying a human-readable name, we are helping future developers out who are
13
// debugging our application.
14
requestName: 'searchBooks'
15
});
Copied!
Every request has two actions: a start action, and an end action. You should specify the name for both of these actions. For more on request actions, refer to the request actions guide.
Note: if you specify the request property on an action, then it will be used as both the key and the name. This API is from Redux Resource < 3.0. Although it will continue to work into the future, it is recommended that you explicitly set requestKey and requestName separately going forward.
Last modified 2yr ago