2017 © Pedro Peláez
 

library smalldb-rest

Simple REST API for Smalldb

image

smalldb/smalldb-rest

Simple REST API for Smalldb

  • Wednesday, August 24, 2016
  • by jkufner
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Smalldb-REST

Simple implementation of REST API for Smalldb., (*1)

Requirements

  • PHP 5.5+
  • libsmalldb

Installation

  1. Use composer install to install all libraries.
  2. Create api-v1.php and api-v1-diagram.php as in examples.
  3. Create state machine definitions in statemachine directory -- see libsmalldb documentation for details.
  4. Before use in production environment change the auth.class option to something less permissive. -- The config.json.php contains option to allow everything. The default is to use CookieAuth class, but that requires some configuration.

Configuration

Configuration is loaded from three JSON files. Later overwrites the previous (using array_replace_recursive function)., (*2)

  • config.json.php in Smalldb-REST's directory to load default values.
  • config.app.json.php in the project's root directory to load application-specific options. This file should be under version control, do not put sensitive informations here.
  • config.local.json.php in the project's root directory to load installation-specific options. This file should NOT be under version control (put it into .gitignore), it is meant to contain sensitive informations.

To achieve forward compatibility of your configuration files do not use whole copy of default config file in your application. Set only changed options instead., (*3)

API Usage

Read state of a state machine (machine ID = "blogpost", 1):, (*4)

HTTP GET /api-v1.php/blogpost/1

Read transition info of a state machine (transition edit):, (*5)

HTTP GET /api-v1.php/blogpost/1!edit

Invoke transition of a state machine (transition edit, parameters are passed via $_POST['args']):, (*6)

HTTP POST /api-v1.php/blogpost/1!edit
Content-Type: application/x-www-form-urlencoded

args[0][title]=Some%20title&args[1][text]=Lorem%20ipsum

List state machines of given type:, (*7)

HTTP GET /api-v1.php/?type=blogpost

State diagram renderer

The second function of the REST API is state diagram renderer. To retrieve state diagram of the blogpost state machine use following HTTP request:, (*8)

HTTP GET /api-v1-diagram.php?machine=blogpost&format=png

This mean you can simply put this HTML to your application:, (*9)

<img src="api-v1-diagram.php?machine=blogpost&format=png" alt="state diagram">

Note: Diagrams are rendered using Graphviz and cached using APC. The dot executable must be somewhere in PHP's PATH., (*10)

LICENSE

Apache 2.0 - see LICENSE file, (*11)

The Versions

24/08 2016

dev-master

9999999-dev https://smalldb.org/

Simple REST API for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Josef Kufner

26/07 2016

v0.5

0.5.0.0 https://smalldb.org/

Simple REST API for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Josef Kufner

25/07 2016

v0.4

0.4.0.0 https://smalldb.org/

Simple REST API for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Josef Kufner

18/06 2016

v0.3

0.3.0.0 https://smalldb.org/

Simple REST API for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Josef Kufner

05/05 2016

v0.2

0.2.0.0

Simple REST API for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

  • cascade/doc-tools dev-master

by Josef Kufner

25/03 2016

v0.1

0.1.0.0

Light REST gateway for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

by Josef Kufner

25/03 2016

v0.0

0.0.0.0

Light REST gateway for Smalldb

  Sources   Download

Apache-2.0

The Requires

 

by Josef Kufner