{"id":17053743,"url":"https://github.com/relrin/aiorest-ws","last_synced_at":"2025-04-12T16:46:05.447Z","repository":{"id":31015764,"uuid":"34574240","full_name":"Relrin/aiorest-ws","owner":"Relrin","description":"REST framework with WebSockets support [inactive]","archived":false,"fork":false,"pushed_at":"2017-10-16T06:52:10.000Z","size":517,"stargazers_count":36,"open_issues_count":0,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-19T04:27:25.388Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Relrin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-25T15:37:37.000Z","updated_at":"2023-03-27T20:45:38.000Z","dependencies_parsed_at":"2022-09-08T17:22:31.808Z","dependency_job_id":null,"html_url":"https://github.com/Relrin/aiorest-ws","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relrin%2Faiorest-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relrin%2Faiorest-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relrin%2Faiorest-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relrin%2Faiorest-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Relrin","download_url":"https://codeload.github.com/Relrin/aiorest-ws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239952606,"owners_count":19723922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T10:13:07.592Z","updated_at":"2025-02-21T19:30:36.014Z","avatar_url":"https://github.com/Relrin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![aiorest-ws logo](https://raw.githubusercontent.com/Relrin/aiorest-ws/master/docs/source/static/logo.png)  [![Build Status](https://travis-ci.org/Relrin/aiorest-ws.svg)](https://travis-ci.org/Relrin/aiorest-ws) [![Coverage Status](https://coveralls.io/repos/Relrin/aiorest-ws/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/Relrin/aiorest-ws?branch=master)\nREST framework with WebSockets support\n\nThis library represents as a flexible toolkit for building Web APIs, which based on the Autobahn.ws and asyncio packages. Use the opportunities of WebSockets for communication between clients and servers, build APIs like in popular frameworks (Django REST, Flask, etc.) with enough simplicity, flexibility and transparency. Develop with a pleasure!\n\nFeatures\n-----\n- Routing\n- Views (function and method-based)\n- Authentication (using JSON Web Token)\n- Customizing behaviour of your application through settings file\n- Compressing messages for minimize of transmitted traffic (if your browser support)\n- Model serializing for Django and SQLAlchemy ORM\n- SSL support\n\nRequirements\n-----\n- Python \u003e= 3.4.2\n- Autobahn.ws == 0.16.0\n\nOptional:\n- SQLAlchemy ORM \u003e= 1.0\n- Django \u003e= 1.9\n\nLicense\n-----\nThe aiorest-ws published under BSD license. For more details read [LICENSE](https://github.com/Relrin/aiorest-ws/blob/master/LICENSE) file.\n\nRoadmap (by priority) to releases:\n------\nv1.2:\n - Wrap ORM calls / serializers into coroutines, so that it won't slow down an event loop\n - Notification support\n \nv1.3:\n - Web browsable API (similar on swagger?)\n \nv1.4:\n - Classes and functions for testing APIs\n - Clients for Python, JavaScript\n\nDocumentation\n-----\nThe latest documentation for the project is available [there](http://aiorest-ws.readthedocs.org/).\n\nContributing\n-----\nRead [CONTRIBUTING](https://github.com/Relrin/aiorest-ws/blob/master/CONTRIBUTING.md) file for more information.\n\nGetting started\n---------------\n#### Client (JavaScript)\n```javascript\nvar ws = null;\nvar isopen = false;\n\nwindow.onload = function() {\n  ws = new WebSocket(\"ws://127.0.0.1:8080\");\n  ws.onopen = function() {\n    console.log(\"Connected!\");\n    isopen = true;\n  };\n\n  ws.onmessage = function(e) {\n    console.log(\"Result: \" +  e.data);\n  };\n\n  ws.onclose = function(e) {\n    console.log(\"Connection closed.\");\n    ws = null;\n    isopen = false;\n  }\n};\n\nfunction sendOnStaticURL() {\n  if (isopen) {\n    ws.send(JSON.stringify({'method': 'GET', 'url': '/hello'}));\n  } else {\n    console.log(\"Connection not opened.\")\n  }\n}\n```\n\n#### Client (Python)\n```python\nimport asyncio\nimport json\n\nfrom autobahn.asyncio.websocket import WebSocketClientProtocol, \\\n    WebSocketClientFactory\n\n\nclass HelloClientProtocol(WebSocketClientProtocol):\n\n    def onOpen(self):\n        request = {'method': 'GET', 'url': '/hello'}\n        self.sendMessage(json.dumps(request).encode('utf8'))\n\n    def onMessage(self, payload, isBinary):\n        message = payload.decode('utf8')\n        print(message)\n\n\nif __name__ == '__main__':\n    factory = WebSocketClientFactory(\"ws://localhost:8080\")\n    factory.protocol = HelloClientProtocol\n\n    loop = asyncio.get_event_loop()\n    coro = loop.create_connection(factory, '127.0.0.1', 8080)\n    loop.run_until_complete(coro)\n    loop.run_forever()\n    loop.close()\n```\n\n#### Server\n```python\nfrom aiorest_ws.app import Application\nfrom aiorest_ws.routers import SimpleRouter\nfrom aiorest_ws.views import MethodBasedView\n\n\nclass HelloWorld(MethodBasedView):\n    def get(self, request, *args, **kwargs):\n        return \"Hello, world!\"\n\n\nrouter = SimpleRouter()\nrouter.register('/hello', HelloWorld, 'GET')\n\n\nif __name__ == '__main__':\n    app = Application()\n    app.run(host='127.0.0.1', port=8080, router=router)\n```\n\nAlso you can look more examples [there](https://github.com/Relrin/aiorest-ws/tree/master/examples).\n\nRunning server with SSL\n-----\n\nAiorest-ws framework support running server with SSL. Just append ```certificate``` and ```key``` options to the ```Application``` constructor:\n\n```python\n# WebSockets will be available on wss://127.0.0.1:8080/api\napp = Application(certificate='path/to/my.crt', key='path/to/my.key')\napp.run(host='127.0.0.1', port=8080, path='api', router=router)\n```\n\nIf you don't have any certificates and keys, but want to run the server with SSL, then generate self-signed certificate via OpenSSL:\n\n```bash\nopenssl genrsa -out server.key 2048\nopenssl req -new -key server.key -out server.csr\nopenssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt\nopenssl x509 -in server.crt -out server.pem\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelrin%2Faiorest-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frelrin%2Faiorest-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelrin%2Faiorest-ws/lists"}