@typeix/resty-aws-lambda
v8.7.0
Published
REST nodejs framework for typescript
Downloads
91
Readme
@typeix/resty Typescript framework for Node.js
- Typeix Official && Documentation
@typeix/resty-aws-lambda
is lambda adapter for resty server
Starters
- TBD
Example Usage
import {
Controller, Inject, ResolvedRoute,
GET, POST, OnError, RootModule, Logger, Router
} from "@typeix/resty";
import {lambdaServer} from "@typeix/resty-aws-lambda";
// define controller
@Controller({
path: "/"
})
class HomeController {
@Inject()
private request: IncomingMessage;
@Inject()
private response: ServerResponse;
@ResolvedRoute()
private route: IResolvedRoute;
@GET()
actionGet() {
return this.route.method.toUpperCase() + " ACTION";
}
@POST()
actionAjax(@RequestBody() body: Buffer) {
return JSON.stringify(body.toString());
}
@OnError("*")
errorCase() {
return "FIRE ERROR CASE";
}
@GET("redirect")
actionRedirect() {
this.response.setHeader("Location", "/mypage");
this.response.writeHead(307);
this.response.end();
}
}
// DEFINE MODULE
@RootModule({
imports: [], // here you can import other modules
shared_providers: [
{
provide: Logger,
useFactory: () => new Logger(Logger.defaultConfig("info"))
},
Router
],
providers: [],
controllers: [HomeController]
})
class ApplicationModule {}
// CREATE SERVER
export const handler = lambdaServer(ApplicationModule);