Skip to content

Commit

Permalink
feat: allow empty request
Browse files Browse the repository at this point in the history
  • Loading branch information
vizee committed Jun 19, 2023
1 parent feb1d61 commit 7468733
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions handlers/jsonapi/jsonapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var _ engine.CallHandler = &Handler{}

type Handler struct {
SurroundOutput [2]string
EmptyRequest bool
}

func (h *Handler) ReadRequest(call *metadata.Call, ctx *engine.Context) ([]byte, error) {
Expand All @@ -20,9 +21,11 @@ func (h *Handler) ReadRequest(call *metadata.Call, ctx *engine.Context) ([]byte,
return nil, err
}
var enc proto.Encoder
err = jsonpb.TranscodeToProto(&enc, jsonlit.NewIter(data), call.In)
if err != nil {
return nil, err
if len(data) > 0 || !h.EmptyRequest {
err := jsonpb.TranscodeToProto(&enc, jsonlit.NewIter(data), call.In)
if err != nil {
return nil, err
}
}
if len(call.Bindings) > 0 {
err = appendBindings(&enc, ctx, call.Bindings)
Expand Down

0 comments on commit 7468733

Please sign in to comment.