The generated server SDK provides a subclass of SchemaServiceHandler. You implement the business logic by providing async functions for every operation defined in your Smithy model. The handler abstracts away HTTP request/response transformations and provides typed inputs and outputs.
When implementing the handler, you provide a handlers object where each key corresponds to an operation. Each handler function receives:
input: The typed input shape for the operation.context: A ServerRequestContext object.userContext: A generic context object provided during instantiation.
// Generated code example
export class GreetingServiceHandler<Context = {}> extends SchemaServiceHandler<Context> {
constructor(
options: SchemaServiceHandlerOptions<Context> & {
handlers: {
SayHello: (
input: SayHelloInput,
context: ServerRequestContext,
userContext: Context
) => Promise<SayHelloOutput>;
GetItem: (input: GetItemInput, context: ServerRequestContext, userContext: Context) => Promise<GetItemOutput>;
};
}
) {
super({
...options,
validationEnabled: options.validationEnabled ?? true,
operationSchemas: options.operationSchemas ?? OPERATION_SCHEMAS,
});
}
public async handle(request: HttpRequest, context: Context): Promise<HttpResponse>;
}