Interface EndpointInterface<D>

interface EndpointInterface<D> {
    DEFAULTS: D & RequestParameters & {
        baseUrl: string;
        headers: RequestHeaders & {
            accept: string;
            user-agent: string;
        };
        mediaType: {
            format: string;
            previews?: string[];
        };
        method: RequestMethod;
        url?: string;
    };
    defaults: (<O>(newDefaults: O) => EndpointInterface<D & O>);
    merge: {
        <R, P>(route: (keyof Endpoints) | R, parameters?: P): D & (R extends keyof Endpoints
            ? Endpoints[R<R>]["request"] & Endpoints[R<R>]["parameters"]
            : EndpointDefaults) & P;
        <P>(options: P): RequestParameters & {
            baseUrl: string;
            headers: RequestHeaders & {
                accept: string;
                user-agent: string;
            };
            mediaType: {
                format: string;
                previews?: string[];
            };
            method: RequestMethod;
            url?: string;
        } & D & P;
        (): D & RequestParameters & {
            baseUrl: string;
            headers: RequestHeaders & {
                accept: string;
                user-agent: string;
            };
            mediaType: {
                format: string;
                previews?: string[];
            };
            method: RequestMethod;
            url?: string;
        };
    };
    parse: (<O>(options: O) => RequestOptions & Pick<O, keyof RequestOptions>);
    <O>(options: O & {
        method?: string;
    } & ("url" extends keyof D
        ? {
            url?: string;
        }
        : {
            url: string;
        })): RequestOptions & Pick<D & O, keyof RequestOptions>;
    <R, P>(route: R | (keyof Endpoints), parameters?: P): (R extends keyof Endpoints
        ? Endpoints[R<R>]["request"]
        : RequestOptions) & Pick<P, keyof RequestOptions>;
}

Type Parameters

  • D extends object = object

Properties

DEFAULTS: D & RequestParameters & {
    baseUrl: string;
    headers: RequestHeaders & {
        accept: string;
        user-agent: string;
    };
    mediaType: {
        format: string;
        previews?: string[];
    };
    method: RequestMethod;
    url?: string;
}

Object with current default route and parameters

defaults: (<O>(newDefaults: O) => EndpointInterface<D & O>)

Returns a new endpoint interface with new defaults

merge: {
    <R, P>(route: (keyof Endpoints) | R, parameters?: P): D & (R extends keyof Endpoints
        ? Endpoints[R<R>]["request"] & Endpoints[R<R>]["parameters"]
        : EndpointDefaults) & P;
    <P>(options: P): RequestParameters & {
        baseUrl: string;
        headers: RequestHeaders & {
            accept: string;
            user-agent: string;
        };
        mediaType: {
            format: string;
            previews?: string[];
        };
        method: RequestMethod;
        url?: string;
    } & D & P;
    (): D & RequestParameters & {
        baseUrl: string;
        headers: RequestHeaders & {
            accept: string;
            user-agent: string;
        };
        mediaType: {
            format: string;
            previews?: string[];
        };
        method: RequestMethod;
        url?: string;
    };
}

Type declaration

    • <R, P>(route, parameters?): D & (R extends keyof Endpoints
          ? Endpoints[R<R>]["request"] & Endpoints[R<R>]["parameters"]
          : EndpointDefaults) & P
    • Merges current endpoint defaults with passed route and parameters, without transforming them into request options.

      Type Parameters

      Parameters

      • route: (keyof Endpoints) | R

        Request method + URL. Example: 'GET /orgs/{org}'

      • Optionalparameters: P

        URL, query or body parameters, as well as headers, mediaType.{format|previews}, request, or baseUrl.

      Returns D & (R extends keyof Endpoints
          ? Endpoints[R<R>]["request"] & Endpoints[R<R>]["parameters"]
          : EndpointDefaults) & P

    • <P>(options): RequestParameters & {
          baseUrl: string;
          headers: RequestHeaders & {
              accept: string;
              user-agent: string;
          };
          mediaType: {
              format: string;
              previews?: string[];
          };
          method: RequestMethod;
          url?: string;
      } & D & P
    • Merges current endpoint defaults with passed route and parameters, without transforming them into request options.

      Type Parameters

      Parameters

      • options: P

      Returns RequestParameters & {
          baseUrl: string;
          headers: RequestHeaders & {
              accept: string;
              user-agent: string;
          };
          mediaType: {
              format: string;
              previews?: string[];
          };
          method: RequestMethod;
          url?: string;
      } & D & P

    • (): D & RequestParameters & {
          baseUrl: string;
          headers: RequestHeaders & {
              accept: string;
              user-agent: string;
          };
          mediaType: {
              format: string;
              previews?: string[];
          };
          method: RequestMethod;
          url?: string;
      }
    • Returns current default options.

      Returns D & RequestParameters & {
          baseUrl: string;
          headers: RequestHeaders & {
              accept: string;
              user-agent: string;
          };
          mediaType: {
              format: string;
              previews?: string[];
          };
          method: RequestMethod;
          url?: string;
      }

      use endpoint.DEFAULTS instead

parse: (<O>(options: O) => RequestOptions & Pick<O, keyof RequestOptions>)

Stateless method to turn endpoint options into request options. Calling endpoint(options) is the same as calling endpoint.parse(endpoint.merge(options)).

Type declaration