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 WebSockets support #114

Closed
wants to merge 4 commits into
base: master
from

Conversation

2 participants
@taoufik07
Copy link
Contributor

taoufik07 commented Oct 21, 2018

I've added websocket support based on starlette, only functions are supported now, I can add classes and improve if you approve this.

In addition to the path, protocol is added now to match routes, so it's fine to have 2 routes with the same path but different protocols

@api.route('/ws')
def test(req, resp):
    """ Http request """
    resp.text = "Hey"

@api.ws_route('/ws')
async def hello(ws):
    await ws.accept()
    await ws.send_text("Hello via websocket!")
    await ws.close()

@api.ws_route('/{greeting}')
async def greeting(ws, greeting):
    await ws.accept()
    while True:
        name = await ws.text()
        await ws.send_text(f"{greeting} {name} via ws!")
    await ws.close()

taoufik07 added some commits Oct 21, 2018

@taoufik07 taoufik07 changed the title Adding websocket support Add websocket support Oct 21, 2018

@taoufik07 taoufik07 referenced this pull request Oct 21, 2018

Closed

Handling WebSockets #111

@taoufik07 taoufik07 changed the title Add websocket support Add WebSockets support Oct 21, 2018

@kennethreitz

This comment has been minimized.

Copy link
Owner

kennethreitz commented Oct 22, 2018

let's get it changed to api.add_route(endpoint, websocket=True)

@taoufik07

This comment has been minimized.

Copy link
Contributor

taoufik07 commented Oct 22, 2018

Alright, I'm on it

@kennethreitz

This comment has been minimized.

Copy link
Owner

kennethreitz commented Oct 22, 2018

@kennethreitz

This comment has been minimized.

Copy link
Owner

kennethreitz commented Oct 22, 2018

test comment

@taoufik07

This comment has been minimized.

Copy link
Contributor

taoufik07 commented Oct 22, 2018

Test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment