menu

Viewflow REST

PRO Only

viewflow.rest package provides a flow implementation with the REST interface.

  • /flows/ - List of available flows
  • /processes/ - List of processes
  • /tasks/ - List of tasks from all flows

Per flow API:

  • /flows/<flow_label>/ - Flow description
  • /flows/<flow_label>/chart/ - SVG flow visualization
  • /processes/<flow_label>/ - List of flow instances
  • /tasks/<flow_label>/ - List of flow tasks

Each flow node could have own API set,

See also the http://demo.viewflow.io/workflow/api/ for the Swagger documentation of each endpoint.

Quick start

viewflow.rest depends on djangorestframework>=3.6 and django-rest-swagger>=2.1

Start with adding viewflow, viewflow.rest and dependencies to the INSTALLED_APPS settings

INSTALLED_APPS = [
    ...,
    'viewflow',
    'viewflow.rest',
    'rest_framework',
    'rest_framework_swagger',
]

Flows could be defined in the <app>/flows.py. Here is the same HelloFlow as in the Quick start but with REST interface.

from viewflow import rest
from viewflow.base import this, Flow
from viewflow.rest import flow, views

from . import models


class HelloRestFlow(Flow):
    process_class = models.HelloRestProcess

    start = flow.Start(
        views.CreateProcessView, fields=['text']
    ).Permission(
        auto_create=True
    ).Next(this.approve)

    approve = flow.View(
        views.UpdateProcessView, fields=['approved'],
        task_description="Message approvement required",
        task_result_summary="Messsage was {{ process.approved|yesno:'Approved,Rejected' }}"
    ).Permission(
        auto_create=True
    ).Next(this.check_approve)

    check_approve = flow.If(
        cond=lambda act: act.process.approved
    ).Then(
        this.send
    ).Else(
        this.end
    )

    send = flow.Handler(
        this.send_message
    ).Next(this.end)

    end = flow.End()

    def send_message(self, activation):
       print(activation.process.text)

In case if you use viewflow.frontend you can register flow in it, and get nice rendered SWAGGER api spec.

from viewflow import rest

@rest.register
class HelloWorldFlow(Flow):
    ...

Don’t forged to enable the frontend, see Quick start for details.

Without frontend you need directly include flowset urls in the django’s URL config.

from django.conf.urls import url, include
from viewflow.rest.viewset import FlowViewSet
from .flows import HelloWorldFlow

hello_urls = FlowViewSet(HelloWorldFlow).urls

urlpatterns = [
    url(r'^workflow/api/helloworld/', include(hello_urls, namespace='helloworld'))
]