///
import { IncomingMessage, ServerResponse } from 'http';
import { RestMiddleware, RestMiddlewareFunction } from './middleware';
import { HttpService } from '../http/http';
import { RestRequest } from './request';
import { RestResponse } from './response';
import { Pattern } from './pattern';
export type RestMiddlewareVariant = RestMiddleware | RestMiddlewareFunction;
export type RestServiceAuthorizeCallback = (clientId: string, request: RestRequest) => Promise | void;
export type RestServiceErrorCallback = (clientId: string, error: unknown) => Promise | void;
export type RestCallback = (request: RestRequest, response: RestResponse) => void;
export type RestRoute = {
method: string;
pattern: Pattern;
middleware: RestMiddleware[];
callback: RestCallback;
};
/** A http rest service that supports standard verb and path routing */
export declare class RestService extends HttpService {
#private;
constructor();
/**
* Subscribes to authorization events. This event is raised before request handlers and is
* used to gather claims prior to executing the request. This callback should throw in
* instances a users cannot be authorized. Any claims gathered during authorization should
* be written to the request.context state to be received by the request handler.
*/
event(event: 'authorize', callback: RestServiceAuthorizeCallback): RestServiceAuthorizeCallback;
/** Subscribes to error events. */
event(event: 'error', callback: RestServiceErrorCallback): RestServiceErrorCallback;
/** Creates a middleware function which is executed on all routes */
use(middleware: RestMiddlewareVariant): this;
/** Creates a http `get` route */
get(pattern: string, middleware: RestMiddlewareVariant[], callback: RestCallback): this;
/** Creates a http `get` route */
get(pattern: string, callback: RestCallback): this;
/** Creates a http `delete` route */
delete(pattern: string, middleware: RestMiddlewareVariant[], handler: RestCallback): this;
/** Creates a http `delete` route */
delete(pattern: string, callback: RestCallback): this;
/** Creates a http `patch` route */
patch(pattern: string, middleware: RestMiddlewareVariant[], handler: RestCallback): this;
/** Creates a http `patch` route */
patch(pattern: string, callback: RestCallback): this;
/** Creates a http `post` route */
post(pattern: string, middleware: RestMiddlewareVariant[], handler: RestCallback): this;
/** Creates a http `post` route */
post(pattern: string, callback: RestCallback): this;
/** Creates a http `put` route */
put(pattern: string, middleware: RestMiddlewareVariant[], handler: RestCallback): this;
/** Creates a http `put` route */
put(pattern: string, callback: RestCallback): this;
/** Accepts an incoming HTTP request and processes it as Rest method call. This method is called automatically by the Host. */
accept(clientId: string, req: IncomingMessage, res: ServerResponse): Promise;
}