You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@xoraes The type is just a standard json.RawMessage for an API Gateway handler. Check out this functional example. It expects a json input of: {"username": "me"}
package main
import (
"encoding/json"
"github.com/apex/go-apex"
)
type ExampleRequest struct {
Username string `json:"username"`
}
type ExampleResponse struct {
Username string `json:"username"`
RequestID string
}
func main() {
apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context)) (interface{}, error) {
var req ExampleRequest
err := json.Unmarshal(event, &req)
if err != nil {
// Don't forget to handle your error
return nil, err
}
return ExampleResponse{
Username: req.Username,
RequestID: ctx.RequestID,
}, nil
}
}
Thanks! Ah, I didn't realize until now that api gateway needed a custom template defined for the json format. Serverless seems to have the ability to push such templates as well. Wonder if that sort of functionality is being considered for apex?
For full swagger and SDK support API Gateway does require this. But more often than not you can get away with not defining templates.
That said, there is a proposal on adding Gateway support with Apex. Specifically the routing layers, not specifically the templating layer. Check out apex/apex/issues/37
Is there a way to handle event from api gateway to lambda ? I have no idea what the json format is for this.
The text was updated successfully, but these errors were encountered: