httpin icon indicating copy to clipboard operation
httpin copied to clipboard

Allow mix of body input and param input

Open snicol opened this issue 1 year ago • 1 comments

Due to this check and potentially missing implementation, a mix of JSON/XML bodies along with other directives is not possible.

This blocks common REST calls, for example creating/updating entities (POST /entity/:id/PUT /entity/:id), where you wish to decode both the URL param :id and the incoming JSON body into a single struct.

snicol avatar Sep 05 '22 13:09 snicol

Hi @snicol , actually httpin does support mixing body input and param input currently. We can use the body directive along with other param input related directives. Let's see an example:

type UpdateUserInput struct {
	ID      string `in:"path=id"` // NOTE: register a path directive before using
	Payload struct {
		Display string `json:"display"`
		Email   string `json:"email"`
		IsAdmin bool   `json:"is_admin"`
	} `in:"body=json"`
}

Please checkout a runable demo here https://go.dev/play/p/kDHljK4PbGF

So, the problem here is that the Body Annotations don't support a mix. I think it's okay now, I will update the docs and make it more clear. Thanks for the report :)

ggicci avatar Sep 08 '22 09:09 ggicci