Skip to content

Comments

✨ Add support for option argument in ORJsonResponse#2584

Closed
RCambier wants to merge 1 commit intofastapi:masterfrom
RCambier:master
Closed

✨ Add support for option argument in ORJsonResponse#2584
RCambier wants to merge 1 commit intofastapi:masterfrom
RCambier:master

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