Skip to main content

AdapterContract

@h4ad/serverless-adapter > AdapterContract

(interface) AdapterContract

The interface that represents a contract between the adapter and the actual implementation of the adapter.

Signature:

export interface AdapterContract<TEvent, TContext, TResponse> 

(method) canHandle

Decide if this adapter can handle a request based in the event payload

Signature:

canHandle(event: unknown, context: TContext, log: ILogger): boolean;

Parameters

ParameterTypeDescription
eventunknownThe event sent by serverless
contextTContextThe context sent by the serverless
logILoggerThe instance of logger

Returns:

boolean

(method) getAdapterName

Get the adapter name

Signature:

getAdapterName(): string;

Returns:

string

(method) getRequest

Maps the serverless payload to an actual request that a framework can handle

Signature:

getRequest(event: TEvent, context: TContext, log: ILogger): AdapterRequest;

Parameters

ParameterTypeDescription
eventTEventThe event sent by serverless
contextTContextThe context sent by the serverless
logILoggerThe instance of logger

Returns:

AdapterRequest

(method) getResponse

Maps the response of the framework to a payload that serverless can handle

Signature:

getResponse(props: GetResponseAdapterProps<TEvent>): TResponse;

Parameters

ParameterTypeDescription
propsGetResponseAdapterProps <TEvent>The props sent by serverless

Returns:

TResponse

(method) onErrorWhileForwarding

When an error occurs while forwarding the request to the framework

Signature:

onErrorWhileForwarding(props: OnErrorProps<TEvent, TResponse>): void;

Parameters

ParameterTypeDescription
propsOnErrorProps <TEvent, TResponse>

Returns:

void

Remarks

You must call resolver.fail or resolver.succeed when implementing this method.