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

    Function defineApi

    • Define an API from arrays of Endpoints and WebSockets. Each array's path literals are captured into the returned ApiDefinition's record keys without also capturing each route's full shape, which keeps TypeScript from getting overwhelmed on large APIs.

      Type Parameters

      • const EndpointPaths extends readonly `/${string}`[] = []
      • const WebSocketPaths extends readonly `/${string}`[] = []

      Parameters

      Returns ApiDefinition<ArrayElement<EndpointPaths>, ArrayElement<WebSocketPaths>>

      import {defineEndpoint, defineApi, HttpMethod, HttpStatus} from '@rest-vir/api';
      import {defineShape} from 'object-shape-tester';

      const usersEndpoint = defineEndpoint({
      path: '/users',
      requests: {
      [HttpMethod.Get]: {
      responses: {
      [HttpStatus.Ok]: {
      responseData: defineShape({users: ['']}),
      },
      },
      },
      },
      });
      const itemsEndpoint = defineEndpoint({
      path: '/items',
      requests: {
      [HttpMethod.Get]: {
      responses: {
      [HttpStatus.Ok]: {
      responseData: defineShape({items: ['']}),
      },
      },
      },
      },
      });

      const result = defineApi({
      apiName: 'my-api',
      endpoints: [
      usersEndpoint,
      itemsEndpoint,
      ],
      webSockets: [],
      });