generateEndpoints
Generic types: | Schemas |
Bulk version of
. Accepts an
object and apply
on each of the entries.
See Also
useEndpointsFactory
Presentation
function generateEndpoints (
invoker: EndpointInvoker ,
schemas: Schemas,
): GenerateEndpoints <Schemas>;
Returns
GenerateEndpoints <Schemas>
Parameters
Name | Type | Description |
---|---|---|
invoker |
| the |
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));