-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Content Negotiation #1319
Comments
@MiltosD you can create custom renderer overwrite |
The example shows that renderers are applied to the api level
However the case is in a |
I ended up with this, not sure if it's a neat approach @api.get("/person/{pk}/", response=Any)
def get_person(request, pk, format: str = None):
person = get_object_or_404(Person, pk=pk)
by_alias = False
if format == "json-ld":
schema: Type[Schema] = PersonSchemaLD
by_alias = True
else:
schema: Type[Schema] = PersonSchema
return schema.from_orm(person).model_dump(
exclude_unset=True,
exclude_none=True,
exclude_defaults=True,
by_alias=by_alias
) It seems to work with |
hard to tell - need to see how exactly your |
Well, a json-ld output contains a plain json {
"name": "John Doe",
"country": "Germany"
} json-ld {
"@context": {
"ex": "http://example.com",
"dct": "http://purl.org/dc/terms/"
},
"@type": "foaf:Person",
"foaf:name": "John Doe",
"ex:country": {
"@type": "dct:Location",
"@id": "http://publications.europa.eu/resource/authority/country/DEU"
}
} The transformation from |
Is it possible to return a different response based on the "Accept" header or a query param e.g. ?format=json-ld
The text was updated successfully, but these errors were encountered: