encoredev / encore

Open Source Development Platform for building robust type-safe distributed systems with declarative infrastructure
https://encore.dev
Mozilla Public License 2.0
7.76k stars 330 forks source link

Porposal: Form url-encoded support in API #1590

Open srs opened 4 days ago

srs commented 4 days ago

I would like the support for other media-types in API specification than application/json. Right now I am using a raw endpoint, but it would be really nice if application/x-www-form-urlencoded would also be supported. Best would be a combination so it's checking both.

How I used to do this before (with echo framework) on certain endpoints - like OAuth token endpoints - would be to annotate request structs with the following:

type GrantTokenParams struct {
  GrantType string `json:"grant_type" form:"grant_type" valid:"required"`
  Username  string `json:"username" form:"username"`
  Password  string `json:"password" form:"password"`
}

The logic would be if the content-type is application/x-www-form-urlencoded it would use the form tags. Else if application/json is the content-type it would behave as normal.

Would this be something that is feasable and/or wanted by others?