feat: migrate force_json_middleware to a named middleware #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
FriendsOfAdonis/FriendsOfAdonis#48
β Type of change
π Description
This pull-request removes the
ForceJsonResponseMiddleware
from the server middlewares and add it to the named middleware. Thestart/routes.ts
is updated accordingly by providing an initialapi
group that uses this middleware.This allows library authors to perform content-negotiation without requiring users to update their existing codebase. And this is a main issue for
@foadonis/openapi
where the content returned depends on theAccept
header allowing them to use the same route for documentation UI and in tools likeopenapi-typescript
.On a side not I think this middleware should not exist at all. Libraries should instead rely on content negotiation as it is already something managed by browsers.
For example, here is the default Accept header on Chrome
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
*/*
With the following example,
Accept
ishtml
on document request andjson
on fetch request.π Checklist