Skip to content

Feature request: Add support for HTTP APIs (API Gateway v2) in Event Handler #4713

@svozza

Description

@svozza

Use case

Currently event handler only supports API Gateway Rest APIs. We should add support for HTTP APIs.

Solution/User Experience

The event source should be transparent to users, they should be able to define handlers that return any valid API Gateway response we support (JSON object, APIGatewayProxyEvent, APIGatewayProxyEventV2, Web Response object) and event handler will automatically detect the input event and convert to the appropriate response.

const app = new Router();

// this returns APIGatewayProxyEventV2
app.get('/test', () => ({
    statusCode: 200,
    body: JSON.stringify({ message: 'success' }),
    headers: { 'content-type': 'application/json' },
    cookies: ['cookie1', 'cookie2'],
}));

const v1Result = await app.resolve(aV1Event, context);

/**
v1Result = {
    "statusCode": 200,
    "headers": {
        "content-type": "application/json",
    },
    "body": "{\"message\":\"success\"}",
    "isBase64Encoded": false,
    "multiValueHeaders": {
        "set-cookie": [
            "cookie1",
            "cookie2"
        ]
    }
}
 */

const v2Result = await app.resolve(aV2Event, context);

/**
v2Result = {
    "statusCode": 200,
    "headers": {
        "content-type": "application/json",
    },
    "body": "{\"message\":\"success\"}",
    "isBase64Encoded": false,
    "cookies": [
        "cookie1",
        "cookie2"
    ]
}
 **/
    

Alternative solutions

Alternative solution would be for customers to have specific resolvers for specific event sources:


const httpApiRouter = new HttpApiRouter()
// will only work with HttpApi events

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Sub-issues

Metadata

Metadata

Assignees

Labels

confirmedThe scope is clear, ready for implementationevent-handlerThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utility

Type

No type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions