Usage
To start to use, first you need to know what you need to import, let's start showing the ServerlessAdapter.
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
We need to pass to Serverless Adapter the instance of your api, let's look an example with:
- Framework: Express.
- Adapters: AWS Api Gateway V2 Adapter.
- Handler: Default Handler.
- Resolver: Promise Resolver.
If you are using Typescript
, imports will only work exactly as in the example
if you set your moduleResolution
to nodenext
or bundler
in your tsconfig.json
.
If you don't want to change this, you should append /lib
after the package name,
like @h4ad/serverless-adapter/lib/frameworks/express/index
.
import { ServerlessAdapter } from '@h4ad/serverless-adapter';
import { ExpressFramework } from '@h4ad/serverless-adapter/frameworks/express';
import { DefaultHandler } from '@h4ad/serverless-adapter/handlers/default';
import { PromiseResolver } from '@h4ad/serverless-adapter/resolvers/promise';
import { ApiGatewayV2Adapter } from '@h4ad/serverless-adapter/adapters/aws';
const express = require('express');
const app = express();
export const handler = ServerlessAdapter.new(app)
.setFramework(new ExpressFramework())
.setHandler(new DefaultHandler())
.setResolver(new PromiseResolver())
.addAdapter(new ApiGatewayV2Adapter())
// if you need more adapters
// just append more `addAdapter` calls
.build();
To know more about the frameworks that you can use, see Frameworks Section.
To know more about the handlers that you can use, see Handlers Section.
To know more about the resolvers that you can use, see Resolvers Section.
To know more about the adapters that you can use, see Adapters Section.