You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The only way it can currently work is to be redundant, what if one wants the entire api to support multiple media types, would we need to replicate all endpoints like this ? (yes, in current state)
There is no drawback to this, one could either introduce a new media_types attribute or allow current media_type to also be a list.
Unresolved questions
Ability to globally specify default media_types that then all endpoints that don't override it, will inherit it and avoid being redundant.
Examples from "others"
How "others" do it is to expose a way to support multiple & custom media types by introducing custom request writers and readers. The idea of a body writer / reader is great. What it could bring as benefits:
ability to register custom media types with their own validation, serialization, deserialization
ability to support multiple media types simultaneously
The Produces / Consumes decorators(attributes in C#) can applied at class level or at method level in controllers, which also solves the problem of having input/ouput formats registered globally, not only at a method level.
Summary
OpenAPI already supports these kind of definitions https://swagger.io/docs/specification/v3_0/media-types/#multiple-media-types
Currently, the only way to support this functionality is to duplicated endpoints (paths/methods)
Basic Example
This is how it could work
The only way it can currently work is to be redundant, what if one wants the entire api to support multiple media types, would we need to replicate all endpoints like this ? (yes, in current state)
Drawbacks and Impact
There is no drawback to this, one could either introduce a new
media_types
attribute or allow currentmedia_type
to also be a list.Unresolved questions
Ability to globally specify default
media_types
that then all endpoints that don't override it, will inherit it and avoid being redundant.Examples from "others"
How "others" do it is to expose a way to support multiple & custom media types by introducing custom request writers and readers. The idea of a body writer / reader is great. What it could bring as benefits:
In .NET a similar pattern is used with body reader/writer and input/output formats and https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/custom-formatters?view=aspnetcore-9.0
Once registered, an endpoint can harness custom media type in a very elegant way:
The
Produces
/Consumes
decorators(attributes in C#) can applied at class level or at method level in controllers, which also solves the problem of having input/ouput formats registered globally, not only at a method level.See discussion https://github.com/orgs/litestar-org/discussions/3330
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: