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 support for option argument in ORJsonResponse #2584

Closed
wants to merge 1 commit into from

Conversation

RCambier
Copy link

✨ Add support for the option argument of orjson when building an ORJsonResponse.

The orjson.dumps() function supports an option argument [1] where flags can be specified.
This PR makes it available when creating am ORJSONResponse.

For example, to support serializing numpy arrays

return ORJSONResponse(content, option=orjson.OPT_SERIALIZE_NUMPY)

[1] https://github.com/ijl/orjson#option

@codecov
Copy link

codecov bot commented Dec 30, 2020

Codecov Report

Merging #2584 (3d4ed7a) into master (5614b94) will decrease coverage by 0.01%.
The diff coverage is 97.36%.

Impacted file tree graph

@@             Coverage Diff             @@
##            master    #2584      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          243      244       +1     
  Lines         7419     7453      +34     
===========================================
+ Hits          7419     7452      +33     
- Misses           0        1       +1     
Impacted Files Coverage Δ
tests/test_default_response_class.py 99.31% <87.50%> (-0.69%) ⬇️
fastapi/responses.py 100.00% <100.00%> (ø)
tests/test_orjson_custom_encoder.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5614b94...3d4ed7a. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 3d4ed7a at: https://5fecb78b042c8a00a4f5db18--fastapi.netlify.app

@ycd
Copy link
Contributor

ycd commented Dec 30, 2020

There is a PR (see: #1846) proposing this.

@RCambier
Copy link
Author

Oh, that's true. Sorry I missed it.

@tiangolo
Copy link
Member

tiangolo commented Sep 1, 2022

Thanks for the interest @RCambier! 🍰

And thanks for the help @ycd!

I added a section to the docs explaining how to make a custom response: https://fastapi.tiangolo.com/advanced/custom-response/#custom-response-class

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

Successfully merging this pull request may close these issues.

3 participants