createEndpointsFactory
Generic types: | Schemas |
Convenience function that creates a factory function, which, once invoked within an InjectionContext
or with dependencies supplied, returns a collection of endpoint functions.
Notes
Can be used as the factory function within
or
declarations.
See Also
- for manually generating endpointsgenerateEndpoints
- higher-level convenience function for using this function within ancreateEndpointsInjectionToken
declarationInjectionToken
Presentation
function createEndpointsFactory (
schemas: Schemas,
): (invoker?: EndpointInvoker ) => GenerateEndpoints <Schemas>;
Returns
(invoker?: EndpointInvoker ) => GenerateEndpoints <Schemas>
Parameters
Name | Type | Description |
---|---|---|
schemas | Schemas | the declaration schema for the intended endpoint functions |
Example usage
const USER_ENDPOINTS = new InjectionToken ("USER_ENDPOINTS", {
factory: createEndpointsFactory ({
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>(),
},
}),
});
private userEndpoints = inject (USER_ENDPOINTS);
this.userEndpoints.list().subscribe(users => console.log(users));
this.userEndpoints.create({ name: 'Char2s' }).subscribe(user => console.log(user));
this.userEndpoints.create({ name: 'Char2s', gender: "Male" }).subscribe(user => console.log(user));