rest-vir - v2.2.0
    Preparing search index...

    Function createRouteDefiners

    • Factory that produces a pair of route definers (defineCustomEndpoint, defineCustomWebSocket) whose inputs are constrained to require a customProps field of the supplied CustomProps shape on every method definition. The returned functions otherwise behave exactly like the standard defineEndpoint and defineWebSocket functions.

      Type Parameters

      • CustomProps extends UnknownObject

      Returns {
          defineCustomEndpoint: <
              const Endpoint extends
                  EndpointDefinitionWithRequiredCustomProps<CustomProps>,
          >(
              endpoint: Readonly<Endpoint>,
          ) => Readonly<Endpoint>;
          defineCustomWebSocket: <
              const ThisWebSocket extends
                  WebSocketDefinitionWithRequiredCustomProps<CustomProps>,
          >(
              webSocket: Readonly<ThisWebSocket>,
          ) => Readonly<ThisWebSocket>;
      }

      import {createRouteDefiners, HttpMethod, HttpStatus} from '@rest-vir/api';

      type MyCustomProps = {
      requiresAuth: boolean;
      };

      export const {defineCustomEndpoint, defineCustomWebSocket} =
      createRouteDefiners<MyCustomProps>();

      const usersEndpoint = defineCustomEndpoint({
      path: '/users',
      requests: {
      [HttpMethod.Get]: {
      customProps: {requiresAuth: true},
      responses: {[HttpStatus.Ok]: {responseData: undefined}},
      },
      },
      });