Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aaravmalani/plugapi
A lightweight, speedy HTTP(S) framework
https://github.com/aaravmalani/plugapi
api api-rest collaborate framework github-pages http https json middleware python python3 server web
Last synced: 10 days ago
JSON representation
A lightweight, speedy HTTP(S) framework
- Host: GitHub
- URL: https://github.com/aaravmalani/plugapi
- Owner: AaravMalani
- License: mit
- Created: 2023-02-22T17:21:33.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-04-08T09:53:55.000Z (almost 2 years ago)
- Last Synced: 2024-12-19T13:03:45.998Z (22 days ago)
- Topics: api, api-rest, collaborate, framework, github-pages, http, https, json, middleware, python, python3, server, web
- Language: Python
- Homepage: https://aaravmalani.github.io/PlugAPI/
- Size: 28.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
PlugAPI : A lightweight, speedy HTTP(S) server
==============================================Requirements
------------- Python 3.6 >=
Usage
-----.. code:: py
from plugapi import Server, JSONResponse, json_middleware
server = Server(443, https=True, certfile='./localhost.pem', keyfile='./localhost-key.pem')
@server.handler(path='/')
def root(req):
return JSONResponse({'a': 'b'})
server.add_middlewares(json_middleware)
server.run()Features
--------- Middleware Middleware are functions accepting the socket, HTTP type,
headers and body and returning a changed headers and body before the
handlers are called They can be added using
``server.add_middlewares(middleware, middleware2, ....)`` For
example, the default JSON middleware is given below.. code-block:: py
def json_middleware(socket: socket.socket, type: str, headers: dict[str, str], body: str | list | dict) -> tuple[dict[str, str], str | list | dict]:
if headers.get("Content-Type", None) == "application/json":
body = json.loads(body)
return headers, body``
There are numerous built-in middlewares including
``multipart_middleware``, ``url_encoded_middleware``,
``cookie_middleware`` and more!
- Different utility responses Responses like ``FileResponse``,
``JSONResponse`` and ``HTMLResponse`` are pre-provided to allow you
to return data without having to set the content typeTo-Do
------ ☐ Websocket support
- ☑ Parameters in paths