Redux Resource
  • Home
  • Introduction
    • Motivation
    • Core Concepts
    • Similar Projects
    • Examples
  • Resources
    • Resource Reducers
    • Resource Objects
    • Meta
    • Lists
    • Modifying Resources
  • Requests
    • Request Objects
    • Keys
    • Names
    • Statuses
    • Request Actions
      • Updating Lists
      • Reading Resources
      • Updating Resources
      • Creating Resources
      • Deleting Resources
  • Other Guides
    • Usage With React
    • Tracking Request Statuses
    • Using Request Statuses
    • Custom Action Types
    • Migration Guides
  • Recipes
    • Forms
    • Canceling Requests
    • Unauthorized Responses
    • User Feedback
    • Related Resources
    • Caching
  • Ecosystem Extras
    • Redux Resource Action Creators
    • Redux Resource XHR
    • Redux Resource Prop Types
    • Redux Resource Plugins
      • HTTP Status Codes
      • Selection
      • Reset
      • Included Resources
  • FAQ
    • General
    • State Tree
    • Actions
    • Lists
  • API Reference
    • resourceReducer
    • getStatus
    • getResources
    • upsertResources
    • setResourceMeta
    • actionTypes
    • requestStatuses
Powered by GitBook
On this page
  • Motivation
  • Specifying a Request Name
  1. Requests

Names

PreviousKeysNextStatuses

Last updated 5 years ago

Request names are a feature that can be useful if you are automatically generating . 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 to specify a name for that request.

import { actionTypes } fom 'redux-resource';
import store from './store';

store.dispatch({
  type: actionTypes.READ_RESOURCES_PENDING,
  resourceType: 'books',

  // In this situation, we are generating a key. It could be a random string of data,
  // which makes debugging hard.
  requestKey: generateRequestKey(/* request data */),

  // By specifying a human-readable name, we are helping future developers out who are
  // debugging our application.
  requestName: 'searchBooks'
});

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.

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 keys
request action
request actions guide