# Class PlatformHandler

Class platform
Module
import { PlatformHandler } from "@tsed/common"
Source/packages/common/src/platform/services/PlatformHandler.ts

# Overview

class PlatformHandler {
    protected injector: InjectorService;
    constructor(injector: InjectorService);
<span class="token function">createHandler</span><span class="token punctuation">(</span>input<span class="token punctuation">:</span> <a href="/api/common/mvc/models/EndpointMetadata.html"><span class="token">EndpointMetadata</span></a> | <a href="/api/common/mvc/models/HandlerMetadata.html"><span class="token">HandlerMetadata</span></a> | <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> PlatformRouteWithoutHandlers<span class="token punctuation">)</span><span class="token punctuation">:</span> Function<span class="token punctuation">;</span>
<span class="token function">createCustomHandler</span><span class="token punctuation">(</span>provider<span class="token punctuation">:</span> <a href="/api/di/class/Provider.html"><span class="token">Provider</span></a>&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">,</span> propertyKey<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Function<span class="token punctuation">;</span>

<span class="token function">createHandlerMetadata</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span> | <a href="/api/common/mvc/models/EndpointMetadata.html"><span class="token">EndpointMetadata</span></a><span class="token punctuation">,</span> routeOptions?<span class="token punctuation">:</span> PlatformRouteWithoutHandlers<span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/common/mvc/models/HandlerMetadata.html"><span class="token">HandlerMetadata</span></a><span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">getArg</span><span class="token punctuation">(</span>type<span class="token punctuation">:</span> <a href="/api/common/mvc/models/ParamTypes.html"><span class="token">ParamTypes</span></a> | <span class="token keyword">string</span><span class="token punctuation">,</span> h<span class="token punctuation">:</span> <a href="/api/common/platform/domain/HandlerContext.html"><span class="token">HandlerContext</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token keyword">protected</span> <span class="token function">onCtxRequest</span><span class="token punctuation">(</span>requestOptions<span class="token punctuation">:</span> <a href="/api/common/platform/services/OnRequestOptions.html"><span class="token">OnRequestOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">onRequest</span><span class="token punctuation">(</span>requestOptions<span class="token punctuation">:</span> <a href="/api/common/platform/services/OnRequestOptions.html"><span class="token">OnRequestOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>
<span class="token keyword">protected</span> <span class="token function">onError</span><span class="token punctuation">(</span>er<span class="token punctuation">:</span> unknown<span class="token punctuation">,</span> requestOptions<span class="token punctuation">:</span> <a href="/api/common/platform/services/OnRequestOptions.html"><span class="token">OnRequestOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">onSuccess</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> requestOptions<span class="token punctuation">:</span> <a href="/api/common/platform/services/OnRequestOptions.html"><span class="token">OnRequestOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">callReturnedMiddleware</span><span class="token punctuation">(</span>middleware<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> ctx<span class="token punctuation">:</span> <a href="/api/common/platform/domain/PlatformContext.html"><span class="token">PlatformContext</span></a><span class="token punctuation">,</span> next<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">flush</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> ctx<span class="token punctuation">:</span> <a href="/api/common/platform/domain/PlatformContext.html"><span class="token">PlatformContext</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">void</span>&gt;<span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">render</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> ctx<span class="token punctuation">:</span> <a href="/api/common/platform/domain/PlatformContext.html"><span class="token">PlatformContext</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Promise&lt;<span class="token keyword">string</span>&gt;<span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">createRawHandler</span><span class="token punctuation">(</span>metadata<span class="token punctuation">:</span> <a href="/api/common/mvc/models/HandlerMetadata.html"><span class="token">HandlerMetadata</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> Function<span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token function">setHeaders</span><span class="token punctuation">(</span>ctx<span class="token punctuation">:</span> <a href="/api/common/platform/domain/PlatformContext.html"><span class="token">PlatformContext</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">void</span><span class="token punctuation">;</span>
<span class="token keyword">protected</span> <span class="token function">next</span><span class="token punctuation">(</span>requestOptions<span class="token punctuation">:</span> <a href="/api/common/platform/services/OnRequestOptions.html"><span class="token">OnRequestOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

}

# Description

Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).

# Members

protected injector: InjectorService;

createHandler(input: EndpointMetadata | HandlerMetadata | any, options?: PlatformRouteWithoutHandlers): Function;

Create a native middleware based on the given metadata and return an instance of HandlerContext


createCustomHandler(provider: Provider<any>, propertyKey: string): Function;

createHandlerMetadata(obj: any | EndpointMetadata, routeOptions?: PlatformRouteWithoutHandlers): HandlerMetadata;

Create handler metadata


protected getArg(type: ParamTypes | string, h: HandlerContext): any;

Get argument from parameter medata or handler context.


protected onCtxRequest(requestOptions: OnRequestOptions): Promise<any>;

protected onRequest(requestOptions: OnRequestOptions): Promise<any>;

Call handler when a request his handle


protected onError(er: unknown, requestOptions: OnRequestOptions): Promise<any>;

protected onSuccess(data: any, requestOptions: OnRequestOptions): Promise<any>;

Manage success scenario


protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any): any;

Call the returned middleware by the handler.


protected flush(data: any, ctx: PlatformContext): Promise<void>;

Send the response to the consumer.


protected render(data: any, ctx: PlatformContext): Promise<string>;

Render the view if the endpoint has a configured view.


protected createRawHandler(metadata: HandlerMetadata): Function;

create Raw handler


protected setHeaders(ctx: PlatformContext): void;

Set response headers


protected next(requestOptions: OnRequestOptions): any;

Other topics