endpoints / Function

generateEndpoints

Generic types:Schemas

Bulk version of generateEndpoint. Accepts an EndpointSchemas object and apply generateEndpoint on each of the entries.

See Also

Presentation

function generateEndpoints(
  invoker: EndpointInvoker,
  schemas: Schemas,
): GenerateEndpoints<Schemas>;

Returns

Parameters

NameTypeDescription
invoker
EndpointInvoker

the EndpointInvoker instance to use under the hood

schemas
Schemas

schema declarations

Example usage

const invoker = inject(EndpointInvoker);
const userEndpoints = generateEndpoints(invoker, {
  list: {
    path: '/api/users',
    method: 'GET',
    params: null,
    response: $type<User[]>(),
  },
  create: {
    path: '/api/users',
    method: 'POST',
    params: { name: $type<string>(), 'gender?': $type<string>() },
    response: $type<User>(),
  },
});
userEndpoints.list().subscribe(users => console.log(users));
userEndpoints.create({ name: 'Char2s' }).subscribe(user => console.log(user));
userEndpoints.create({ name: 'Char2s', gender: "Male" }).subscribe(user => console.log(user));