Skip to main content

Unofficial hypermedia form extension for dougrain.

Project description

https://travis-ci.org/weluse/dougrain-forms.png?branch=master

A generator for hypermedia forms, following an unofficial draft by Mike Kelly. The format is roughly based on this Gist by Mike Kelly.

Installation

pip install dougrain-forms

Usage

Example:

from dougrain_forms import FormsMixin

class FormsDocument(Document, FormsMixin):
    pass

doc = FormsDocument.empty()
doc.add_link('self', '/foo')

doc.set_form(
    'attack',
    '/attacks',
    headers={
        'Content-Type': 'application/json'
    },
    method='POST',
    schema=ATTACK_SCHEMA
)

print(doc.as_object())

Output:

{
    "_forms": {
        "attack": {
            "headers": {
                "Content-Type": "application/json"
            },
            "href": "/attacks",
            "method": "POST",
            "schema": {
                "required": [
                    "name",
                    "damage"
                ],
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "damage": {
                        "minimum": 0,
                        "type": "integer",
                        "description": "How much does it hurt?"
                    }
                },
                "title": "Damage Schema"
            }
        }
    },
    "_links": {
        "self": {
            "href": "/foo"
        }
    }
}

API

By mixing in FormMixin into your document, you get three new methods:

  • set_form(self, rel, target, **kwargs)

  • delete_form(self, rel)

  • form(self, href, **kwargs)

Until real docs have been written, take a look at the source.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dougrain-forms-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file dougrain-forms-0.2.0.tar.gz.

File metadata

File hashes

Hashes for dougrain-forms-0.2.0.tar.gz
Algorithm Hash digest
SHA256 13a14cd807d7794c9465a267a36ef4c238167ebdd6ff8a01f4df4d0f91bd660f
MD5 4f39d9c4b130b0889e5f1cce31c4bcc5
BLAKE2b-256 d54f055e1ca3975adb141e9ccbbdef413676983df3a7c7d002d65d0b1b7911f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page