[](https://travis-ci.org/GetBlimp/django-websocket-request) [](http://badge.fury.io/py/django-websocket-request)
## Overview
This package provides support for transport agnostic routing to allow the Django's request/response lifecycle to automatically WebSocket messages. It borrows a WebSocket message format from [Sails.js](http://sailsjs.org/).
## Installation
Install using `pip`...
```
$ pip install django-websocket-request
```
## Usage
### ws.py
```python
# Set Django Environment
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
from wsrequest import WebSocketRequest
message = '{"method": "GET", "url": "/api/projects/"}'
request = WebSocketRequest(message)
response = request.get_response()
print(response.content)
```
### WebSocket message format
The method key can be any HTTP method: GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS. The url key is an absolute URL without the domain name. The data key is an optional dictionary in which the key-value pairs in used to create the method’s data payload. The token key is also optional, and used to recreate an HTTP Authorization header, Authorization: JWT YOUR_TOKEN_HERE. If you're using Django REST framework, you might like to check out [django-rest-framework-jwt](https://github.com/GetBlimp/django-rest-framework-jwt).
```json
{
"method": "POST",
"url": "/api/companies/",
"data": {
"name": "Acme Inc."
},
"token": "MY_JSON_WEB_TOKEN"
}
```
## Live Demo
Check out [GetBlimp/django-websocket-request-example](https://github.com/GetBlimp/django-websocket-request-example) for an example implementation and a live demo.
## Example implementation with sockjs + tornado
```python
import os
import json
from tornado import web, ioloop
from sockjs.tornado import SockJSRouter, SockJSConnection
# Set Django Environment
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
from wsrequest import WebSocketRequest
class RESTAPIConnection(SockJSConnection):
def on_open(self, info):
self.send(json.dumps({'connected': True}))
def on_message(self, data):
response = WebSocketRequest(data).get_response()
self.send(response.content)
if __name__ == '__main__':
import logging
port = 8080
logging.getLogger().setLevel(logging.INFO)
Router = SockJSRouter(RESTAPIConnection, '/ws/api')
app = web.Application(Router.urls)
app.listen(port)
logging.info(" [*] Listening on 0.0.0.0:{}".format(port))
ioloop.IOLoop.instance().start()
```
Metadata
Release files for django-websocket-request 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-websocket-request-0.1.1.tar.gz | 9.3 kB | Without provenance | Details for django-websocket-request-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_websocket_request-0.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_websocket_request-0.1.1-py2.py3-none-any.whl |
Total release size: 19.6 kB
Release files / django-websocket-request-0.1.1.tar.gz
| Download URL | django-websocket-request-0.1.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3daadc93a75a9542f83d6e6d267e2626afc1e687fb3d3aae345419f84244175a
|
|
BLAKE2b-256 checksum How to use checksums |
408e3053f9c4b4d887e5983a74483d4ac37dcdaae1c827da30764bc4ac3b23ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_websocket_request-0.1.1-py2.py3-none-any.whl
| Download URL | django_websocket_request-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0c610e06c4c31dead4f63c9f048e4648a1c8f6d2459fe182c9955d0638fb6998
|
|
BLAKE2b-256 checksum How to use checksums |
f189acc7bfc7267b06832d00553d2277483b2256d2839826ef84ba95f4c9692b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-websocket-request 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.