Goodies

Autodoc

When enabled (default on development env), you can access {host}:{port}/_autodoc/browse/.

_images/autodoc.png

It contains

  • searchable method list
  • selected method details like
    • file / method (clickable link, just click and editor of your choice will open file on that function)
    • path
    • documentation
    • python code
    • validator code
    • decorators
    • ExceptionMaps

Accept header parsing

When you enable it, CodernityREST will aromatically respond in format selected in Accept header. Then you can do:

#    Copyright 2011-2014 Codernity (http://codernity.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from CodernityREST.misc.accept_view import View
from CodernityREST.router_ex import R


class HtmlResponseMixin(object):

    def format_html(self, ctx, data):
        return '''<html>
                    <head><title>%s</title></head>
                    <body><strong>%s</strong></body>
                  </html>''' % (ctx.req.env['PATH_INFO'], data)

    format_html.output_content_type = 'text/html'


class HelloWorldView(View, HtmlResponseMixin):

    def process(self, ctx):
        return 'Hello world!'

    def format_plain(self, ctx, data):
        return data


def get_routes():
    ret = []
    with R('/test') as r:
        with r('/class', a=4):
            r.s('GET', '/', HelloWorldView())
    ret.append(r)

    return ret

It will use rendering function that user requested (via Accept header). Everything happens automatically. Just create class that inherits View.

Req dumper

If enabled (by default on development environment), any exception that will occur in your app, will be dumped and will be available via HTTP interface, all local variables, whole stack etc. By default last 100 are kept.

The URL is {host}:{port}/_req_dumper/list for list of dumps and {host}:{port}/_req_dumper?dump_id="{id}" for single dump.