createEndpointsInjectionToken
Generic types: | Schemas |
Convenience function that creates a typed
with a default value of a collection of endpoints generated from the given schemas, through
.
See Also
- for manually generating endpointsgenerateEndpoints
- lower-level convenience functioncreateEndpointsFactory
Presentation
function createEndpointsInjectionToken (
name: string,
schemas: Schemas,
): InjectionToken <GenerateEndpoints <Schemas>>;
Returns
InjectionToken <GenerateEndpoints <Schemas>>
Parameters
Name | Type | Description |
---|---|---|
name | string | |
schemas | Schemas |
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));