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: [],
});
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.