rest-vir - v1.0.0
    Preparing search index...

    Type Alias EndpointInit<AllowedMethods, RequestDataShape, ResponseDataShape>

    The type for setting up an individual endpoint, used in defineService.

    type EndpointInit<
        AllowedMethods extends
            RequireAtLeastOne<Record<HttpMethod, boolean>> = RequireAtLeastOne<
            Record<HttpMethod, boolean>,
        >,
        RequestDataShape = unknown,
        ResponseDataShape = unknown,
    > = {
        bypassResponseValidation?: boolean;
        customProps?: Record<PropertyKey, unknown>;
        methods: AllowedMethods;
        requestDataShape: RequestDataShape;
        requiredClientOrigin?: OriginRequirement;
        responseDataShape: ResponseDataShape;
        searchParamsShape?: unknown;
    }

    Type Parameters

    • AllowedMethods extends RequireAtLeastOne<Record<HttpMethod, boolean>> = RequireAtLeastOne<Record<HttpMethod, boolean>>
    • RequestDataShape = unknown
    • ResponseDataShape = unknown
    Index

    Properties

    bypassResponseValidation?: boolean

    Set this to true to bypass shape validation. You might want to use this, for example, for large data sets that are being slow.

    customProps?: Record<PropertyKey, unknown>

    Any additional data that you wish to attach to this endpoint. This won't be used by the service at all, it's merely a place for you to place extra data which will be passed along to your endpoint implementations.

    All allowed (or not allowed) HTTP methods for this endpoint. Set true for each allowed method and omit or set false for each blocked method.

    requestDataShape: RequestDataShape

    Shape definition for request data. Set to undefined for no request data.

    See the object-shape-tester package for extra details on defining a shape.

    requiredClientOrigin?: OriginRequirement

    Set a required client origin for this endpoint.

    • If this is omitted, the service's origin requirement is used instead.
    • If this is explicitly set to undefined, this endpoint allows any origins (regardless of the service's origin requirement).
    • Any other set value overrides the service's origin requirement (if it has any).
    responseDataShape: ResponseDataShape

    Shape definition for response data. Set to undefined for no response data.

    See the object-shape-tester package for extra details on defining a shape.

    searchParamsShape?: unknown

    A shape used to verify search params. This should match the entire search params object.

    Note the following:

    • Search param values will always be in an array
    • Elements in search param value arrays will always be strings
    import {exact, enumShape} from 'object-shape-tester';

    const partialEndpointInit = {
    searchParamsShape: {
    // use `tupleShape` to ensure there's exactly one entry for this search param
    userId: tupleShape(enumShape(MyEnum)),
    date: tupleShape(exact('2')),
    // don't use `tupleShape` here so that there can be any number of entries
    colors: [''],
    },
    };