Interface PAPIBuilder<Root>

Builder interface to define an API

interface PAPIBuilder<Root> {
    root: Root;
    build(config?): PAPICaller<Root>;
    delete<Resp>(resp): PAPIBuilder<Expand<Root & Record<typeof $DELETE, Record<typeof $response, Resp>>>>;
    delete<Resp, Delete>(resp, endpoint): PAPIBuilder<Expand<Root & Record<typeof $DELETE, Expand<Record<typeof $response, Resp> & EndpointDefBuilderOut<Delete>>>>>;
    get<Resp>(resp): PAPIBuilder<Expand<Root & Record<typeof $GET, Record<typeof $response, Resp>>>>;
    get<Resp, Get>(resp, endpoint): PAPIBuilder<Expand<Root & Record<typeof $GET, Expand<Record<typeof $response, Resp> & EndpointDefBuilderOut<Get>>>>>;
    patch<Resp>(resp): PAPIBuilder<Expand<Root & Record<typeof $PATCH, Record<typeof $response, Resp>>>>;
    patch<Resp, Patch>(resp, endpoint): PAPIBuilder<Expand<Root & Record<typeof $PATCH, Expand<Record<typeof $response, Resp> & EndpointDefBuilderOut<Patch>>>>>;
    path<const PathName, Path>(pathname, path): PAPIBuilder<Expand<Root & Record<PathName, APIDefBuilderFnOut<Path>>>>;
    post<Resp>(resp): PAPIBuilder<Expand<Root & Record<typeof $POST, Record<typeof $response, Resp>>>>;
    post<Resp, Post>(resp, endpoint): PAPIBuilder<Expand<Root & Record<typeof $POST, Expand<Record<typeof $response, Resp> & EndpointDefBuilderOut<Post>>>>>;
    put<Resp>(resp): PAPIBuilder<Expand<Root & Record<typeof $PUT, Record<typeof $response, Resp>>>>;
    put<Resp, Put>(resp, endpoint): PAPIBuilder<Expand<Root & Record<typeof $PUT, Expand<Record<typeof $response, Resp> & EndpointDefBuilderOut<Put>>>>>;
    shared<const Paths, Shared>(paths, shared): PAPIBuilder<Expand<Root & Record<Paths[number], APIDefBuilderFnOut<Shared>>>>;
    slug<Slug>(slug): PAPIBuilder<Expand<Root & Record<typeof $slug, APIDefBuilderFnOut<Slug>>>>;
}

Type Parameters

Properties

root: Root

Definition shape of an API or a path of an API

Methods

  • Define a new path segment of an API. A path segment is each section of an API's endpoint URL separated by a / that has a fixed value -- for instance, in the fake API https://fake.api/v2/user/:userId, the values of v2 and user are path segments

    A path segment's definition may contain other paths/shareds/slugs as well as endpoint definitions.

    Type Parameters

    Parameters

    • pathname: PathName

      Path segment of the url

    • path: Path

      Builder function that further defines the shape of the path

    Returns PAPIBuilder<Expand<Root & Record<PathName, APIDefBuilderFnOut<Path>>>>

    Example: Using the path function

    papi('https://jsonplaceholder.typicode.com')
    .path('user', user => user...);
  • Define a new shared segment of an API. A shared segment is each section of an API's endpoint URL separated by a / that can represent multiple values from a selected set -- for instance, in the fake API https://fake.api/v2/categories/:category, where only the values "comments", "photos", and "users" are valid, the value of :category is a shared segment

    A shared segment's definition may contain other paths/shareds/slugs as well as endpoint definitions.

    Type Parameters

    Parameters

    • paths: Paths

      List of paths represented by the shared segment

    • shared: Shared

      Builder function that further defines the shape of the shared segment

    Returns PAPIBuilder<Expand<Root & Record<Paths[number], APIDefBuilderFnOut<Shared>>>>

    Example: Using the shared function

    papi('https://jsonplaceholder.typicode.com')
    .shared(userId => userId...);
  • Define a new slug segment of an API. A slug segment is each section of an API's endpoint URL separated by a / that can represent multiple values -- for instance, in the fake API https://fake.api/v2/user/:userId, the value of :userId is a slug segment

    A slug segment's definition may contain other paths/shareds/slugs as well as endpoint definitions.

    Type Parameters

    Parameters

    • slug: Slug

      Builder function that further defines the shape of the slug

    Returns PAPIBuilder<Expand<Root & Record<typeof $slug, APIDefBuilderFnOut<Slug>>>>

    Example: Using the slug function

    papi('https://jsonplaceholder.typicode.com')
    .slug(userId => userId...);