This release is a pre-release and may not be stable for production use.
==========================
Package for working with Django urls/views and request/response validation in more convenient way.
Inspired by beautiful [hug](https://github.com/timothycrosley/hug).
Getting Started
===================
Simple API building example with django-hug
In your views module create routes and couple API endpoints.
```python
# views.py
import django_hug
from marshmallow import fields
routes = django_hug.Routes()
@routes.get('new/<int:year>/')
def simple(request, year, month: int):
return {"year": year, "month": month}
@routes.get('happy/<int:year>/')
def mm_field(request, year, month: fields.Int(validate=Range(min=1, max=12)) = 1):
return [year, month]
```
In your urls.py specify new endpoints
```python
from . import views
urlpatterns = views.routes.urls()
```
Thats all, now you can make requests to new API endpoints with convenient data validation
```bash
curl http://127.0.0.1:8000/new/2019/?month=133
>> {"year": 2019, "month": 133}
```
and nice errors handling
```bash
curl http://127.0.0.1:8000/happy/2019/?month=133
>> {"errors": {"month": ["Must be between 1 and 12."]}}
```
Usage
=====
#### Regexp path
You can also use regexp path
```python
@routes.get("(?P<year>[0-9]{4})/", re=True)
def index3(request, year, name: str):
loc = locals()
del loc["request"]
return loc
```
#### Directives
Use builtin directive `body` to validate whole POST request
```python
# views.py
import django_hug
from marshmallow import Schema, fields
routes = django_hug.Routes(prefix="api")
class RespSchema(Schema):
id = fields.Int(required=True)
quantity = fields.Int(required=True)
@routes.post("test/")
def view(request, body: RespSchema()):
return body
```
#### Routes prefix
Specify prefix in Routes object to add prefix to all urls
```python
# views.py
import django_hug
routes = django_hug.Routes(prefix="api")
@routes.get('<int:year>/')
def api_method(request, year, month: int = 1):
return {"year": year, "month": month}
```
```bash
curl http://127.0.0.1:8000/api/2019/
>> {"year": 2019, "month": 1}
```
#### Types
__Coming soon__
#### Response and request formatting
Underscore/camelcase transform
__Coming soon__
#### To start example app
```bash
make venv
source activate
cd example
./manage.py runserver
```
Attention! Work In Progress
==
#### TODO
* Full support various view decorators (test_decorators)
* Support multiple routes for one view (?)
* Add exception handler
* Take into account content type for response
* Cleanup tests
Metadata
Release files for django-hug 0.1b1
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-hug-0.1b1.tar.gz | 8.7 kB | Without provenance | Details for django-hug-0.1b1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_hug-0.1b1-py3-none-any.whl | Python 3 | none | any | Details for django_hug-0.1b1-py3-none-any.whl |
Total release size: 25.0 kB
Release files / django-hug-0.1b1.tar.gz
| Download URL | django-hug-0.1b1.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38ed25bd4e16e6e837f7abcea7c2fe8942f9a6190021c0ad5b2dcc6712f8c2b2
|
|
BLAKE2b-256 checksum How to use checksums |
cdcc2496e546733e34903c6482060ed05c56c7e643dc2b8d9b8bf71b3baeb4d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / django_hug-0.1b1-py3-none-any.whl
| Download URL | django_hug-0.1b1-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83173e09591ca33fb7231fb5a2cd2e4fa944420507928699ee62c6ddfecf1c82
|
|
BLAKE2b-256 checksum How to use checksums |
298d0e06f8966c8c134bab9ffa2f82ee4b1c92365e29a32d3f55667dcbc10b76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for django-hug 0.1b1
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.