User Tools

Site Tools


Apis application

This application provides support for building APIs in a pluggable way. So far only has support for REST-style APIs.

In order to be automatically handled for this application, each app should provide its part of the API implementation in its own module. More descriptive examples of how to register REST-style resources are provided on the following section.

Resource registration pattern module provides support for pluggable resources on the REST API.

  1. It takes care of the url management:
    # controller/
    from apis import rest
    urlpatterns = patterns('',
        url(r'^admin/', include(,
        url(r'^api/', include(rest.api.urls)),
  2. Automatically find resources registred on app/ modules. An examples:
    # nodes/
    from apis import rest
    class NodeList(generics.ListCreateAPIView):
        model = Node
        serializer_class = NodeSerializer
    class NodeDetail(generics.RetrieveUpdateDestroyAPIView):
        model = Node
        serializer_class = NodeSerializerapi.register(NodeResource)
    # for each resource you have to provide a ListView and a DetailView:
    rest.api.register(NodeList, NodeDetail)
  3. Aggregate new fields to existing serializers (useful for Tinc pluggable app):
    # tinc/
    from apis import rest
    class TincClientSerializer(serializers.ModelSerializer):
        connect_to = TincAddressSerializer()
        island = IslandSerializer()
        name = serializers.CharField()
        class Meta:
            model = TincClient
            exclude = ('object_id', 'content_type', 'id')
    rest.api.aggregate(Server, TincClientSerializer, name='tinc')
  4. Automatically generates the Base resource which basically lists all the registred resources.
soft/server-apps-apis.txt · Last modified: 2012/10/16 15:46 by marcay