Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add special case for application/x-www-form-encoded bodies #210

Open
urandom2 opened this issue Jul 21, 2020 · 1 comment
Open

add special case for application/x-www-form-encoded bodies #210

urandom2 opened this issue Jul 21, 2020 · 1 comment

Comments

@urandom2
Copy link

Form encoding is a well structured, flat key-value pair interface. Much like application/json, we should be able to break out a case for a more ergonomic interface. I propose the following:


  1. If you have more than one request body type, meaning more than one media
    type, you will have a generic handler of this form:

     AddPet(ctx context.Context, contentType string, body io.Reader)
    
  2. If you have only a JSON request body, you will get:

     AddPet(ctx context.Context, body NewPet)
    
  3. If you have only a form url encoding request body, you will get:

     AddPet(ctx context.Context, body NewPet)
    
  4. If you have multiple request body types, which include a JSON or form encoded type you will get multiple functions. We've chosen to give the JSON version a shorter name, as we work with JSON and don't want to wear out our keyboards.

     AddPet(ctx context.Context, body NewPet)
     AddPetForm(ctx context.Context, body NewPet)
     AddPetWithBody(ctx context.Context, contentType string, body io.Reader)
    
@deepmap-marcinr
Copy link
Contributor

I'm thinking the fix for this kind of issue is to allow the registering of unmarshal helper functions keyed off content-type, and we simply provide some pre-defined ones, but users are free to add their own.

That would be a very breaking API change, though. I'm going to start filing tasks for a V2 version of this library, where we will also get strict about semver for generated code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants