A very simple REST server
Project description
Kaa
A very simple python server framework for 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.2.tar.gz
(9.0 kB
view hashes)
Built Distribution
Close
Hashes for kaa_rest_server-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 017e5849407aeb5484beaca429a0f23015ff96a42364ae923f7e8c600f95c4f3 |
|
MD5 | 499d6a525001963660a6852f68b2615a |
|
BLAKE2b-256 | b90170c5e731519e2e447de0d3fe92566653525e43e6cc83edba09baaaf69ad1 |