Skip to content

Create a WebSocketAPIRoute class to support #166 - #178

Merged
tiangolo merged 7 commits into
fastapi:masterfrom
jekirl:master
May 24, 2019
Merged

tiangolo merged 7 commits into
fastapi:masterfrom
jekirl:master

Conversation

@jekirl

@jekirl jekirl commented Apr 22, 2019 •

Copy link
Copy Markdown
Contributor

Initial work at adding dependencies to websocket routes (see #166 ). The way I added it in is probably less than ideal, but figured I would open the PR for now. Still to be done is adding in tests for other dependencies such as Security, Query, Cookie, etc...

jekirl added 2 commits April 22, 2019 16:25
…ments to a websocket callable, initial testing for headers
@codecov

codecov Bot commented Apr 22, 2019

Copy link
Copy Markdown

Codecov Report

Merging #178 into master will decrease coverage by 0.04%.
The diff coverage is 95.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #178      +/-   ##
==========================================
- Coverage     100%   99.95%   -0.05%     
==========================================
  Files         164      164              
  Lines        4035     4079      +44     
==========================================
+ Hits         4035     4077      +42     
- Misses          0        2       +2
Impacted Files Coverage Δ
fastapi/dependencies/utils.py 100% <100%> (ø) ⬆️
tests/test_ws_router.py 100% <100%> (ø) ⬆️
fastapi/routing.py 98.76% <88.88%> (-1.24%) ⬇️

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 8880c4c...caf616b. Read the comment docs.

@codecov

codecov Bot commented Apr 22, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #178 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #178    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files         164    181    +17     
  Lines        4035   4500   +465     
======================================
+ Hits         4035   4500   +465
Impacted Files Coverage Δ
fastapi/applications.py 100% <100%> (ø) ⬆️
docs/src/websockets/tutorial001.py 100% <100%> (ø)
docs/src/websockets/tutorial002.py 100% <100%> (ø)
fastapi/routing.py 100% <100%> (ø) ⬆️
.../test_tutorial/test_websockets/test_tutorial002.py 100% <100%> (ø)
fastapi/dependencies/models.py 100% <100%> (ø) ⬆️
.../test_tutorial/test_websockets/test_tutorial001.py 100% <100%> (ø)
fastapi/dependencies/utils.py 100% <100%> (ø) ⬆️
tests/test_ws_router.py 100% <100%> (ø) ⬆️
fastapi/openapi/docs.py 100% <0%> (ø) ⬆️
... and 33 more

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 8880c4c...d523236. Read the comment docs.

@tiangolo

Copy link
Copy Markdown
Member

Nice! I'll review it soon.

@jekirl

jekirl commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

I have a few more things I could add to the PR that we are using internally. i.e. pydantic validated message types for websocket input/output. But I am not sure if others would find that functionality useful.

@tiangolo

Copy link
Copy Markdown
Member

Sounds very interesting. I think we could have some optional mechanism to do it (not enforcing it on all cases).

How does it look like? I mean, the code a developer writes using your extensions.

@jekirl

jekirl commented May 14, 2019

Copy link
Copy Markdown
Contributor Author

I will try to put together a sample project soon™ ...

@tiangolo
tiangolo merged commit b087246 into fastapi:master May 24, 2019
@jekirl

jekirl commented May 24, 2019

Copy link
Copy Markdown
Contributor Author

Circling back on this, been in our backlog. Semi tricky to separate out the functionality, but haven't forgotten about it!

@tiangolo

tiangolo commented May 24, 2019 •

Copy link
Copy Markdown
Member

Cool! I just refactored this PR a bit, added docs, updated tests and merged.

I also started Kludex/starlette#527. Once (and if) it is accepted, it will allow us to raise inside WebSocket endpoints, sub-dependencies, and handle errors more cleanly.

This is just released in version 0.24.0, the new docs are here: https://fastapi.tiangolo.com/tutorial/websockets/

I'll update the internals to include Kludex/starlette#527 later, but this works already.

Thanks a lot for your work! 🎉 🚀 🌮

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.

2 participants