Skip to content

Enhancement: Utility to get data on all available endpoints #2367

@tuzmusic

Description

@tuzmusic

It's useful to have urls for API endpoints stored as constants in an app, so that they can be reused safely. For example, I might use API.getSomeResource.url as the query property in an RTK Query endpoint, and also use API.getSomeResource.url as the url argument for mocking with, say, MirageJS, cy.intercept (in Cypress.io), or an other mocking framework.

Since the baseApi winds up being a catalog of all the endpoints used, it would be very helpful if it exposed information about those endpoints. There is indeed already baseApi.endpoints but it doesn't include this data.

Perhaps baseApi.endpoints could add the following fields: (excuse the imprecise type annotations)

type ExtendedEndpointLogic = EndpointLogic & {
  query: typeof createApi.endpoints[].query
  method: RESTMethod // "get", "post", etc.
  // and perhaps even!
  transformResponse: typeof createApi.endpoints[].transformResponse
}

(Indeed, query would be a function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions