koajs / joi-router

Configurable, input and output validated routing for koa
MIT License
451 stars 96 forks source link

Feature: Allow multiple types #74

Open pke opened 5 years ago

pke commented 5 years ago

It seems it would make sense to allow clients to request resources with either json, url encoded or form data. All three could be allowed by the API. Currently the type argument in the validation is only accepting a string. I could create a PR that would accept an array too.

pke commented 5 years ago

Thinking about it, why is it even relevant in which format the clients sends the data? If this middleware can decode it and provide it as structured data in the body then the route should not dictate a singular format. What do you think?

Saghen commented 5 years ago

I went ahead and implemented this on my fork of the project: https://github.com/Saghen/joi-router

Please note though that this fork is currently a heavy wip.

pke commented 5 years ago

:+1: Which commit brought that feature into your fork?

Saghen commented 5 years ago

Here it is

aheckmann commented 5 years ago

A goal of this module is to fail as fast as possible on invalid input. No guessing means less bugs in my APIs. Accepting multiple formats by using an array seems like a good idea.

mlshv commented 5 years ago

Any updates on the issue?