generateEndpoint
Generic types: | Schema |
Resolves an
object into a function, which accepts an object of parameters as declared, if any, and returns an observable response.
See Also
Presentation
function generateEndpoint (
invoker: EndpointInvoker ,
schema: Schema,
): GenerateEndpoint <Schema>;
Returns
GenerateEndpoint <Schema>
Parameters
Name | Type | Description |
---|---|---|
invoker |
| the |
schema | Schema | the declaration schema of the endpoint |
Example usage
const invoker = inject (EndpointInvoker );
const endpoint = generateEndpoint (invoker, {
path: '/api/users',
method: 'GET',
params: null,
response: $type <{ id: 'number', name: 'string' }>(),
})
endpoint().subscribe(response => {
console.log(response.id);
console.log(response.name);
})
const invoker = inject (EndpointInvoker );
const endpoint = generateEndpoint (invoker, {
path: '/api/users',
method: 'POST',
params: { name: $type <string>(), 'gender?': $type <string>() },
response: $type <{ id: 'number', name: 'string' }>(),
})
endpoint({ name: "Char2s" }).subscribe(response => {
console.log(response.id);
console.log(response.name);
})