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
Optional body parameters can be done with ftl.Option. I assume it can be done with query params too:
type GetRequest struct {
UserID string `json:"userId"`
PostID string `json:"postId"`
Tag ftl.Option[string] `json:"tag"`
}
// Example: curl -i http://localhost:8891/http/users/123/posts?postId=456&tag=foo
//
//ftl:ingress http GET /http/users/{userId}/posts
func Get(ctx context.Context, req builtin.HttpRequest[GetRequest]) (builtin.HttpResponse[GetResponse, ErrorResponse], error) {
if req.Body.UserID == "000" {
return builtin.HttpResponse[GetResponse, ErrorResponse]{
Error: ftl.Some(ErrorResponse{
Error: "User not found",
}),
}, nil
}
tag := req.Body.Tag.Default("No value")
return builtin.HttpResponse[GetResponse, ErrorResponse]{
Headers: map[string][]string{"Get": {"Header from FTL"}},
Body: ftl.Some(GetResponse{
Message: fmt.Sprintf("Got userId %s, postId %s, tag %s", req.Body.UserID, req.Body.PostID, tag),
Nested: Nested{GoodStuff: "Nested Good Stuff"},
}),
}, nil
}
But it does't:
% curl "http://localhost:8891/http/users/1/posts?postId=2&tag=foo"
{"msg":"Got userId 1, postId 2, tag No value","nested":{"good_stuff":"Nested Good Stuff"}}%
The text was updated successfully, but these errors were encountered:
Optional body parameters can be done with
ftl.Option
. I assume it can be done with query params too:But it does't:
The text was updated successfully, but these errors were encountered: