nameko-http
Http utilities for Nameko built-in HTTP extension
Quickstart
Install from pypi:
$ pip install nameko-http
Example:
# helloworld.py
import json
from werkzeug.wrappers import Response
from nameko_http import api
from nameko_http.exceptions import HttpError
class HttpForbidden(HttpError):
# Any Http Exceptions that are going to be raised need to inherit
# from base exception class: HttpError.
error_code = 'FORBIDDEN'
status_code = 403
class ExampleService:
name = "exampleservice"
@api('GET', '/privileged')
def forbidden(self, request):
raise HttpForbidden('You shall not access')
@api('GET', '/foo', cors_enabled=True)
def get_foo(self, request):
return Response(
json.dumps({'value': 'foo'}),
status=200,
mimetype='application/json'
)
$ nameko run helloworld
starting services: exampleservice
$ curl -i localhost:8000/privileged
HTTP/1.1 403 FORBIDDEN
Content-Type: application/json
Content-Lentgh: 61
Date: Thu, 01 Nov 2018 14:21:14 GMT
{"error_code": "FORBIDDEN", "reason": "You shall not access"}
curl -i localhost:8000/foo
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Authorization, Content-Type, Accept
Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Credentials: false
Date: Thu, 01 Nov 2018 14:23:21 GMT
{"value": "foo"}
Credits
This package was created with Cookiecutter_ and the audreyr/cookiecutter-pypackage_ project template.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _audreyr/cookiecutter-pypackage: https://github.com/audreyr/cookiecutter-pypackage
History
0.1.5 (2018-11-29)
- Fix for empty request body when request method POST, PUT or PATCH.
0.1.4 (2018-11-20)
0.1.3 (2018-11-05)
- fix bumping issue
0.1.2 (2018-11-05)
- Pass cors headers when exceptions
- Added handling for expected exceptions
0.1.1 (2018-11-01)
- Added utility method for making responses
- README.md update with example usage
- Drop support for python:2.7
0.1.0 (2018-10-31)
- First release.
Metadata
Release files for nameko-http 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nameko_http-0.1.7-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Release files / nameko_http-0.1.7-py2.py3-none-any.whl
| Download URL | nameko_http-0.1.7-py2.py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c5c3a7983a4e09a48899b258d625e4c8fdf64e6f94bd3354e1db4a75750702f9
|
|
BLAKE2b-256 checksum How to use checksums |
77b56331853ae54800c45c37cf22365e1607a4f12371eb743c275abe896ed9cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|