smalldb / smalldb-rest
Simple REST API for Smalldb
Installs: 28
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
pkg:composer/smalldb/smalldb-rest
Requires
- smalldb/flupdo: *
- smalldb/libsmalldb: >=0.4
Requires (Dev)
- smalldb/doc-tools: dev-master
README
Simple implementation of REST API for Smalldb.
Requirements
- PHP 5.5+
- libsmalldb
Installation
- Use
composer installto install all libraries. - Create
api-v1.phpandapi-v1-diagram.phpas in examples. - Create state machine definitions in
statemachinedirectory -- see libsmalldb documentation for details. - Before use in production environment change the
auth.classoption to something less permissive. -- Theconfig.json.phpcontains option to allow everything. The default is to useCookieAuthclass, but that requires some configuration.
Configuration
Configuration is loaded from three JSON files. Later overwrites the previous
(using array_replace_recursive function).
config.json.phpin Smalldb-REST's directory to load default values.config.app.json.phpin 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.phpin 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.
API Usage
Read state of a state machine (machine ID = "blogpost", 1):
HTTP GET /api-v1.php/blogpost/1
Read transition info of a state machine (transition edit):
HTTP GET /api-v1.php/blogpost/1!edit
Invoke transition of a state machine (transition edit, parameters are passed
via $_POST['args']):
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:
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:
HTTP GET /api-v1-diagram.php?machine=blogpost&format=png
This mean you can simply put this HTML to your application:
<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.
LICENSE
Apache 2.0 - see LICENSE file