typedrequest/ts/typedrequest.classes.typedrequest.ts
2019-08-31 23:14:46 +02:00

28 lines
716 B
TypeScript

import * as plugins from './typedrequest.plugins';
export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest> {
public urlEndPoint: string;
public method: string;
// STATIC
constructor(urlEndPointArg: string, methodArg: T['method']) {
this.urlEndPoint = urlEndPointArg;
this.method = methodArg;
}
/**
* firest the request
*/
public async fire(fireArg: T['request']): Promise<T['response']> {
const response = await plugins.smartrequest.request(this.urlEndPoint, {
method: 'POST',
requestBody: JSON.stringify({
method: this.method,
request: fireArg,
response: null
})
});
return response.body.response;
}
}