Here is a sample for running your application with zero configuration.


from nanohttp import Controller, RestController, context, html, json, \

tips = [
    dict(id=i, title="Tip %s" % i) for i in range(1, 4)

class TipsControllers(RestController):
    def get(self, tip_id: int = None):
        if tip_id is None:
            return tips

        for tip in tips:
            if tip['id'] == int(tip_id):
                return tip

        raise HTTPNotFound(f'Tip: {tip_id} is not found')

    def post(self):
        tip_title = context.form.get('title')
        # Updating the tips global variable
        tip_id = len(tips)+1
        tips.append(dict(id=tip_id, title=tip_title))
        raise HTTPFound('/tips/')

class Root(Controller):
    tips = TipsControllers()

    @html(prevent_form='400 Form Not Allowed')
    def index(self):
        yield """
        <html><head><title>nanohttp Demo</title></head><body>
        <form method="POST" action="/tips/">
            <input type="text" name="title" />
            <input type="submit" value="Update" />
$ nanohttp demo


from nanohttp import quickstart, configure


Do you need a WSGI application?


from nanohttp import configure, Application

configure(init_value='<yaml config string>', files=['path/to/config.file', '...'], dirs=['path/to/config/directory', '...'])
app = Application(root=Root())
# Pass the ``app`` to any ``WSGI`` server you want.

Serve it by gunicorn:

gunicorn --reload wsgi:app


nanohttp CLI command and quickstart automatically will set your root controller to application.

See also

If your application is ready to production, read more about wsgi and Deploy.