A very simple REST server
Project description
Kaa
A very simple python server framework from REST applications.
Starting
Requirements
- pyYaml for OpenApi output
- Mock for testing
Main files
Definition
Requires file definition.py at the top of the project:
import logging
NAME = 'Simple kaa Server' # Your project name
VERSION = 'v1.0' # Version
SERVER = 'app.Server' # Module and main class
LOG = logging.getLogger()
DEBUG = True
ENABLE_CORS = False
Server file
Requires a simple file to start server (kaa.py)
import importlib
from kaa.cli import Cli, Server
# For WSGI application
def application(env, start_response):
return Server().serve(env, start_response)
# For development
if __name__ == "__main__":
cli = Cli()
cli.execute()
Main classes
(file app.py)
This class initializes Kaa for each http request
from kaa import Kaa, KaaServer
class Server(KaaServer):
def get_kaa(self, env, start_response) -> Kaa:
kaa = Kaa(env, start_response)
kaa.register_resources('app', 'AppResources')
return kaa
This class define your resources
from kaa import GET, PATH, Resources, Response, Status
class AppResources(Resources):
@GET
@PATH('/')
def basic_resource(self, **params):
return Response(Status.OK).json({
'message': 'your response'
})
Starting server
$ python kaa.py serve
By default host is 127.0.0.0 and port is 8086
Start with diferent host and port:
$ python kaa.py serve host:port
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kaa-rest-server-0.1.1.tar.gz
(9.0 kB
view hashes)
Built Distribution
Close
Hashes for kaa_rest_server-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f15d0dec53e22a70d4b967eb96ebcf554c7fc6ee997e2ff8fb23df29a5c308c |
|
MD5 | 2f1183054070aafdf0c2df050109ef5b |
|
BLAKE2b-256 | b3980a3c6f191cb3b80a800a2ccf20c8c07a49fd03ba5a6b9ac8bbe13e25d858 |