Puente is a lightweight routing library for AWS Lambda using API Gateway events in Go. It allows you to define routes and handle HTTP methods easily.
- Define routes for different HTTP methods (GET, POST, PUT, PATCH, DELETE).
- Group routes for better organization.
- Custom error handling.
- Middleware support. (e.g. logging, authentication etc.)
- Lambda function URL request handling natively.
To install Puente, run:
go get github.com/nejdetkadir/puente
Here's a simple example to get you started:
package main
import (
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/nejdetkadir/puente"
)
func main() {
lambda.Start(handler)
}
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
router := puente.New()
router.Get("/hello", func(request events.APIGatewayProxyRequest) events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: "Hello, World!",
}
})
return router.ListenAPIGateway(request), nil
}
You can group routes to keep your code organized:
group := router.Group("/api")
group.Get("/users", func(request events.APIGatewayProxyRequest) events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: "List of users",
}
})
You can define custom error handling for your routes:
router.OnError(func(err error) events.APIGatewayProxyResponse {
return events.APIGatewayProxyResponse{
StatusCode: 500,
Body: "Internal Server Error",
}
})
Unit tests are provided to ensure the functionality of the package. To run the tests, use:
go test ./...
Bug reports and pull requests are welcome on GitHub at https://github.com/nejdetkadir/puente. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
This project is licensed under the MIT License. See the LICENSE file for details.