Skip to main content

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)

Uploaded Source

Built Distribution

kaa_rest_server-0.1.2-py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page