Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

https://secure.travis-ci.org/plone/plone.rest.png?branch=master https://coveralls.io/repos/plone/plone.rest/badge.png?branch=master Code Health Downloads Latest Version Egg Status License

Plone REST

Purpose

plone.rest allows you to use HTTP verbs such as GET, POST, PUT, DELETE, etc. in Plone.

REST stands for Representational State Transfer. It is a software architectural principle to create loosely coupled web APIs.

plone.rest provides the basic infrastructure that allows us to build RESTful endpoints in Plone.

The reason for separating this infrastructure into a separate package from the ‘main’ full Plone REST API is so you can create alternative endpoints tailored to specific usecases. A number of these specific endpoints are already in active use.

Audience

plone.rest is for experienced web developers who want to build their own HTTP/REST endpoints on top of Plone.

If you want to use a ready-made full RESTful Plone API, you should use plone.restapi. That package uses, and depends upon, this one.

Features

  • Registering RESTful service endpoints for the following HTTP verbs:

    • GET

    • POST

    • PUT

    • DELETE

    • PATCH

    • OPTIONS

  • Support for Dexterity and Archetypes-based content objects

  • Content negotiation (‘application/json’ is currently the only format supported).

  • Named services allows to register service endpoints for custom URLs

Registering RESTful Service Endpoints

plone.rest allows you to register HTTP verbs for Plone content with ZCML.

This is how you would register a PATCH request on Dexterity content:

<plone:service
  method="PATCH"
  for="plone.dexterity.interfaces.IDexterityContent"
  factory=".service.Patch"
  />

You have to specify the HTTP verb (GET, POST, PUT, DELETE, HEAD, OPTIONS), the interface for the content objects and the factory class that actually returns the content.

The factory class needs to inherit from the plone.rest ‘Service’ class and to implement a render method that returns a list or a dict:

from plone.rest import Service

class Patch(Service):

    def render(self):
        return {'message': 'PATCH: Hello World!'}

The return value (list or dict) will be automatically transformed into JSON.

Content Negotiation

To access the service endpoint we just created we have to send a GET request to a Dexterity object by setting the ‘Accept’ header to ‘application/json’:

PATCH /Plone/doc1 HTTP/1.1
Host: localhost:8080
Accept: application/json

The server then will respond with ‘200 OK’:

HTTP/1.1 200 OK
Content-Type: application/json

{
  'message': 'PATCH: Hello World!'
}

You can try this out on the command line:

$ http --auth admin:admin PATCH localhost:8080/Plone/doc1 Accept:application/json

Here is a list of examples for all supported HTTP verbs:

GET:

$ http --auth admin:admin GET localhost:8080/Plone/doc1 Accept:application/json

POST:

$ http --auth admin:admin POST localhost:8080/Plone/doc1 Accept:application/json

PUT:

$ http --auth admin:admin PUT localhost:8080/Plone/doc1 Accept:application/json

DELETE:

$ http --auth admin:admin DELETE localhost:8080/Plone/doc1 Accept:application/json

PATCH:

$ http --auth admin:admin PATCH localhost:8080/Plone/doc1 Accept:application/json

OPTIONS:

$ http --auth admin:admin OPTIONS localhost:8080/Plone/doc1 Accept:application/json

Named Services

Named services can be registered by providing a ‘name’ attribute in the service directive:

<plone:service
  method="GET"
  for="Products.CMFPlone.interfaces.IPloneSiteRoot"
  factory=".service.Search"
  name="search"
  />

This registers a service endpoint accessible at the site root using the following request:

GET /Plone/search HTTP/1.1
Host: localhost:8080
Accept: application/json

Installation

Install plone.rest by adding it to your buildout:

[buildout]

 ...

 eggs =
     plone.rest

and then running “bin/buildout”

Contribute

Support

This package is maintained by Timo Stollenwerk <tisto@plone.org> and Ramon Navarro Bosch <ramon.nb@gmail.com>.

If you are having issues, please let us know.

License

The project is licensed under the GPLv2.

Changelog

1.0a3 (2015-12-16)

1.0a2 (2015-12-10)

  • Simplify patch of DynamicType pre-traversal hook and actually make it work with Archetypes. [buchi]

  • Render errors as JSON. [jone]

  • Add support for named services which allows registering services like GET /Plone/search or GET /Plone/doc1/versions/1 using a ‘name’ attribute. [jone, lukasgraf, buchi]

  • Remove “layer” from service directive for now, because it is not yet implemented properly. [jone]

1.0a1 (2015-08-01)

  • Initial release. [bloodbare, timo]

Release files for plone.rest 1.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plone.rest 1.0a3
File Size Uploaded
plone.rest-1.0a3.zip 96.6 kB Details

Release files / plone.rest-1.0a3.zip

Download URL plone.rest-1.0a3.zip
Size 96.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4f176dfd6d084ee0c97d4773abc8330d7326cf7c679b1046de5fe1c73e24ed51
BLAKE2b-256 checksum
How to use checksums
64ca401b0a8c4170ebfc5ca3f1edd9cc3a6dd8af832aa89fd7ea0c3cc652aa11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

6.0.0

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.1

1 release file

1.5.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.0

2 release files

1.1.1

1 release file

1.0.0

1 release file

This release

1.0a3 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page