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

Install

pip install kaa-rest-server

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 = 'server.Server'  # Module and main class

LOG = logging.getLogger()
DEBUG = True
ENABLE_CORS = False

Application file

Requires a simple file to start server (app.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 server.py)

This class initializes Kaa for each http request

from kaa import Kaa, KaaServer

class Server(KaaServer):

    def register_resources(self):
        self.kaa.register_resources('app', 'AppResources')

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.1 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.2.0.tar.gz (10.0 kB view hashes)

Uploaded Source

Built Distribution

kaa_rest_server-0.2.0-py3-none-any.whl (12.4 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