Welcome to restae’s documentation!

restae is a light framework build on the top of webapp2 and is meant tu be used on Google App Engine.

Terms of content

Installation

Install with Pip.

$ pip install restae

If you want, you can always download the latest bleeding edge from GitHub:

$ git clone git://github.com/tolsac/restae.git
$ cd restae
$ ./setup.py install

Restae supports Python 2.6, 2.7.

Examples

Let’s take a look at a quick example of using restae to build a simple model-backed API. We’ll create a read-write API for accessing information on the users of our project. Any global settings for the API are kept in a single configuration dictionary named RESTAE_SETTINGS.

import webapp2

from google.appengine.ext import ndb

from restae.handlers import APIModelHandler
from restae.router import Router
from restae.serializers import ModelSerializer


class User(ndb.Model):
    email = ndb.StringProperty()
    first_name = ndb.StringProperty()
    last_name = ndb.StringProperty()


class UserModelSerializer(ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class Handler(APIModelHandler):
    queryset = User.query()
    serializer_class = UserModelSerializer


router = Router()
router.register('user', Handler)

app = webapp2.WSGIApplication(router.urls)

This will generate the following routes

GET     /user/                         \ list action
GET     /user                          \ list action (idem without trailing slash)

GET     /user/<user key urlsafe>/      \ retrieve action
GET     /user/<user key urlsafe>       \ retrieve action (idem without trailing slash)

POST    /user/                         \ create action
POST    /user                          \ create action (idem without trailing slash)

PUT     /user/<user key urlsafe>/      \ update action
PUT     /user/<user key urlsafe>       \ update action (idem without trailing slash)

PATCH   /user/<user key urlsafe>/      \ partial_update action
PATCH   /user/<user key urlsafe>       \ partial_update action (idem without trailing slash)

DELETE  /user/<user key urlsafe>/      \ destroy action
DELETE  /user/<user key urlsafe>       \ destroy action (idem without trailing slash)

Handlers

Basically you do not need this API but if you are curious feel free to check it out.

BaseHandler

APIHandler

APIModelListHandler

APIModelCreateHandler

APIModelRetrieveHandler

APIModelUpdateHandler

APIModelPatchHandler

APIModelDestroyHandler

APIModelMixinHandler

APIModelHandler

Router

Router class definitions

Route

class restae.router.Route(**kwargs)[source]

A route mapping representation contains the URL, METHOD and route type

Url

class restae.router.Url(**kwargs)[source]

An URL representation contains the Route and the destination Handler

Router

class restae.router.Router[source]

The default router

get_lookup_regex(handler)[source]

Given a handler, return the portion of URL regex that is used to match against a single instance.

get_method_map(handler, method_map)[source]

Given an handler, and a mapping of http methods to actions, return a new mapping which only includes any mappings that are actually implemented by the viewset.

get_routes(handler)[source]

Augment self.routes with any dynamically generated routes. Returns a list of the Route class.

get_urls()[source]

Use the registered handlers to generate a list of URL patterns.

Middleware

Middleware class definitions

Middleware

class restae.middleware.Middleware[source]

Base middleware class

process_request(request)[source]

Will be called before handler

process_response(request, response)[source]

Will be called after handler

Response

Response class definitions

CorsResponse

class restae.response.CorsResponse(*args, **kwargs)[source]

JsonResponse

class restae.response.JsonResponse(*args, **kwargs)[source]

Serializers

Serializers class definitions

Field

class restae.serializers.Field(*args, **kwargs)[source]
serialize()[source]

—> si y’a un data={} on veux verifier que les fields sont bien types, pas de manquant etc.. —> si pas de data, on a un objet et on veux le mettre en dict

BooleanField

class restae.serializers.BooleanField(*args, **kwargs)[source]
base_type

alias of __builtin__.bool

IntegerField

class restae.serializers.IntegerField(*args, **kwargs)[source]
base_type

alias of __builtin__.int

StringField

class restae.serializers.StringField(*args, **kwargs)[source]
base_type

alias of __builtin__.str

FloatField

class restae.serializers.FloatField(*args, **kwargs)[source]
base_type

alias of __builtin__.float

KeyField

class restae.serializers.KeyField(*args, **kwargs)[source]

DatetimeField

class restae.serializers.DatetimeField(*args, **kwargs)[source]
base_type

alias of datetime.datetime

Serializer

class restae.serializers.Serializer(*args, **kwargs)[source]

ModelSerializer

class restae.serializers.ModelSerializer(*args, **kwargs)[source]

Decorators

Decorators class definitions

action

Decorators

restae.decorators.action(methods=None, detail=None, url_path=None, param_name=None)[source]

Mark a Handler method as a routable action. Set the detail boolean to determine if this action should apply to instance/detail requests or collection/list requests.

Indices and tables