Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Author: Ramon Bartl
Version: 0.7.0

Latest Build Status

Build Status


An extensible Plone JSON API Framework


This Package allows Users to expose content information via JSON.


This project was born in 2012, out of the need for a data source to build a network based iOS application. Or more precise, I wanted to learn iOS programming and wanted to knit my own JSON API:)

I know, it is a little bit awkward to provide an own routing mechanism for Plone which dipatches the request after the ZPublisher did its job, but it worked and thus, I did it.


Since the API comes after the ZPublisher, it can only make use of HTTP GET and HTTP POST methods. The other methods will never reach the API View.

Be aware that the API View comes with the permission zope2.View, so you need to programmatically check for the correct permissions on your custom routes.



The plone.jsonapi.core should work with Plone 3, 4 and 5 on Python 3.


Users of Plone 3 should pin the versions of simplejson and Werkzeug.


versions = versions

simplejson = 2.0.9
werkzeug = 0.7.2


There official release is on pypi, so you have to simply include plone.jsonapi.core to your buildout config.



eggs =


After installation, the API View is available as a Browser View on your Plone site with the name @@API, for example http://localhost:8080/Plone/@@API.

API Framework

The main work is done in the plone.jsonapi.core.browser.api module. This module dispatches the incoming request and dispatches it to an endpoint function.

The API Router

The Router is responsible to manage and maintain API routes to endpoints.

Routes get defined by so called "Route Providers".

A route provider is either a named Utility class, which implements the IRouteProvider interface, or simply a function, which is registered via the add_route decorator.

Basic Example

The most basic route provider is simply a decorated function:

from plone.jsonapi.core import router

@router.add_route("/hello/<string:name>", "hello", methods=["GET"])
def hello(context, request, name="world"):
    return {"hello": name}

The passed in context and request gets passed of the @@API View. It can be used to query Plone tools or other utilities or adapters.

A more complex Example

In this Example, we're going to add a route provider named my_routes. This route provider gets registered as an named Utility.

To do so, we add a module called to our package and add the following code:

from zope import interface
from plone.jsonapi.core.interfaces import IRouteProvider

class ExampleRoutes(object):

    def initialize(self, context, request):
        """ called by the json api framework"""

    def routes(self):
        return (
            ("/hello/<string:name>", "hello", self.json_hello, dict(methods=['GET'])),

    def json_hello(self, context, request, name="world"):
        return {"hello": name}

To register the Utility, we add this directive to the configure.zcml file:

<!-- Extension point for custom routes -->
    factory=".routes.ExampleRoutes" />

Or use grok:

from five import grok


grok.global_utility(ExampleRoutes, name="my_routes", direct=False)

Each route provider gets initialized with the context and the request in a method called initialize. This method gets called by the API framework.

Our route provider has to contain a routes property or method. It should return a tuple of route definitions. Each route definition contains the url rule (/hello), an endpoint name (hello), a method to be called when the url matches (self.json_hello) and an additional dictionary with routing options

The options dictionary get directly passed to the routing mechanism of Werkzeug. For details, see:


plone.jsonapi.core comes with a default implementation of the router. This router uses the routing mechanism provided by Werkzeug. It is possible to plug in a more sophisticated router by using the ZCA. Simply configure a class which implements the IRouter interface.

To test this route, browse to the /hello API url:



    _runtime: 0.00025200843811035156,
    hello: "JSON Plone API"


If you design your custom RESTful JSON API, you probably want to insert URLs to your specified resources, e.g:


The plone.jsonapi.core.router module comes with a url_for method.

So when you want to insert the URL for the defined hello endpoint, you simply add it like this:

from plone.jsonapi.core import router

@router.add_route("/hello/<string:name>", "hello", methods=["GET"])
def hello(context, request, name="world"):
    return {
        "url": router.url_for("hello", values={"name": name}, force_external=True),
        "hello": name,

It builds the URLs using the build method of the MapAdapter of Werkzeug. For details, see

The resulting JSON will look like this:



    url: "http://localhost:8080/Plone/@@API/hello/world",
    runtime: 0.002997875213623047,
    hello: "world"


You have to handle the permissions for your routes manually. so if you would like to restrict the permission of the hello route, you have to do something like this:

from AccessControl import getSecurityManager
from AccessControl import Unauthorized

from plone.jsonapi.core import router

@router.add_route("/hello/<string:name>", "hello", methods=["GET"])
def hello(context, request, name="world"):

    if not getSecurityManager().checkPermission("ViewHelloAPI", context):
        raise Unauthorized("You don't have the 'ViewHelloAPI' permission")

    return {
        "url": router.url_for("hello", values={"name": name}, force_external=True),
        "hello": name,


    runtime: 0.0021250247955322266,
    success: false,
    error: "You don't have the 'ViewHelloAPI' permission"


Plone JSONAPI Core Framework




No packages published