io-ts-serverless-handler
A simple wrapper for Serverless Framework HTTP handlers
to remove the boilerplate of using io-ts codecs to validate and extract request parameters.
Usage
Install with npm/yarn:
$ yarn add io-ts-serverless-handler
Create a file where you configure the wrapper function and export it:
import { configureWrapper } from "io-ts-serverless-handler";
export const codecHandler = configureWrapper({
});
Wrap your handler functions with the wrapper function:
import { codecHandler } from "./codec-handler.ts";
export const getUsers = codecHandler(
{
queryParameters: t.partial({
pageSize: t.number,
pageNumber: t.number
}),
pathParameters: t.type({
userId: t.string
})
},
async ({
queryParameters: { pageSize, pageNumber },
pathParameters: { userId }
}) => {
return userService.getUser(userId, pageNumber, pageSize);
}
);
Roadmap
- Better documentation
- Support io-ts/fp-ts 2.x
- CI/CD
- Support for serverless handlers for providers other than AWS