RESTService
About
REST Service is small library. This is template for REST services. REST Service is wrapper for aiohttp framework. This library wraps class Application from framework and adds middleware for handle exceptions and make web response from it. Also throws config file to web handlers.
Installation
pip install restservice
Classes
- RESTService - class makes aiohttp app with middleware who catchs exceptions and makes web response
- RESTConfig - class makes config and gets params from yaml file
- RESTHandler - class wraps aiohttp View class and throws config in handler
- RESTError - class for generate exceptions
Example
from aiohttp.web import json_response, RouteTableDef
from restservice import RESTError, RESTService, RESTConfig, RESTHandler
routes = RouteTableDef()
# Create class Config with params as annotation
# config gets env variable ENVIRONMENT and find params in yaml file
# if config not found param with current env config gets param from DEFAULT or return None
class Config(RESTConfig):
DB: str
# make func handler
async def func_handler(request):
return json_response(await request.json())
# make class handler with config
@routes.view(r'/test/{user_id}')
class TestHandler(RESTHandler):
# GET handler
async def get(self):
user_id = self.request.match_info.get('user_id')
db_path = self.config.DB
if user_id == 'exc':
raise RESTError('USER_ID_ERROR', 'User id error.')
return json_response({'user_id': user_id, 'db_path': db_path})
if __name__ == '__main__':
app = RESTService() # create aiohttp app with middleware
app.config = Config('config.yaml') # add config
app.add_routes(routes) # add route table
app.router.add_get('/example', func_handler) # add handler
app.start() # run app
example request not found page
curl http://localhost:8080/404
response
{
"error": "HTTP_NOT_FOUND",
"message": "Http not found.",
"detail": null
}
Metadata
Release files for restservice 0.1.10
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 |
|---|---|---|---|---|
| restservice-0.1.10.tar.gz | 3.2 kB | Without provenance | Details for restservice-0.1.10.tar.gz |
Release files / restservice-0.1.10.tar.gz
| Download URL | restservice-0.1.10.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3abd00a9367b91af325eaec2229ccaf929e9e31d642601d39f4815e7f5500165
|
|
BLAKE2b-256 checksum How to use checksums |
f9bc96bd7a8d5a1612f5de97cb241acf82fe8e39fe9e426358ed1d7b5f9f3282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Security for restservice 0.1.10
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.