REST

ETS JSON

Simple table-oriented service implementation:

-module(users). -behaviour(rest). -compile({parse_transform, rest}). -include("users.hrl"). -export([init/0, populate/1, exists/1, get/0, get/1, post/1, delete/1]). -rest_record(user). init() -> ets:new(users, [public, named_table, {keypos, #user.id}]). populate(Users) -> ets:insert(users, Users). exists(Id) -> ets:member(users, wf:to_list(Id)). get() -> ets:tab2list(users). get(Id) -> [User] = ets:lookup(users, wf:to_list(Id)), User. delete(Id) -> ets:delete(users, wf:to_list(Id)). post(#user{} = User) -> ets:insert(users, User); post(Data) -> post(from_json(Data, #user{})).

METHODS

$ curl -i -X POST -d "id=vlad" localhost:8005/rest/users $ curl -i -X POST -d "id=doxtop" localhost:8005/rest/users $ curl -i -X GET localhost:8005/rest/users $ curl -i -X PUT -d "id=5HT" localhost:8005/rest/users/vlad $ curl -i -X GET localhost:8005/rest/users/5HT $ curl -i -X DELETE localhost:8005/rest/users/5HT

KVS JSON

Automatiс chain-oriented API service implementation. Plug your Erlang HRL schema to mix.exs

{:bpe, "~> 4.9.18"}, {:erp, "~> 0.10.3"},

or rebar.config:

{bpe, ".*", {git, "git://github.com/synrc/bpe", {tag,"master"}}}, {erp, ".*", {git, "git://github.com/erpuno/erp", {tag,"master"}}},

ERP JSON

Retrieve ERP organizational structure:

$ curl -X GET http://localhost:8005/rest/kvs/0/erp/group {"\/erp\/group":[{"name":"Quanterall","url":"quanterall.com", "location":[],"type":[]}]}

Retrive all invoice payments for Stamp project of FinaTech company:

$ curl -X GET http://localhost:8005/rest/kvs/0/plm/FinaTech-Stamps/income {"\/plm\/FinaTech-Stamps\/income":[{"invoice":"APR-2018-PAY-FTST","account":[], "subaccount":[],"volume":{"fraction":0,"digits":12000},"price":{"fraction":0, "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice": "AUG-2018-PAY-FTST","account":[],"subaccount":[],"volume":{"fraction":0, "digits":12000},"price":{"fraction":0,"digits":1},"instrument":"USD","type": "crypto","from":[],"to":[]},{"invoice":"FEB-2018-PAY-FTST","account":[], "subaccount":[],"volume":{"fraction":0,"digits":7000},"price":{"fraction":0, "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice": "JAN-2018-PAY-FTST","account":[],"subaccount":[],"volume":{"fraction":0,"digits": 5000},"price":{"fraction":0,"digits":1},"instrument":"USD","type":"crypto","from": [],"to":[]},{"invoice":"JUL-2018-PAY-FTST","account":[],"subaccount":[],"volume": {"fraction":0,"digits":10000},"price":{"fraction":0,"digits":1},"instrument": "USD","type":"crypto","from":[],"to":[]},{"invoice":"JUN-2018-PAY-FTST", "account":[],"subaccount":[],"volume":{"fraction":0,"digits":10000},"price": {"fraction":0,"digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]}, {"invoice":"MAR-2018-PAY-FTST","account":[],"subaccount":[],"volume": {"fraction":0,"digits":10000},"price":{"fraction":0,"digits":1},"instrument": "USD","type":"crypto","from":[],"to":[]},{"invoice":"MAY-2018-PAY-FTST", "account":[],"subaccount":[],"volume":{"fraction":0,"digits":15000}, "price":{"fraction":0,"digits":1},"instrument":"USD","type":"crypto", "from":[],"to":[]},{"invoice":"SEP-2018-PAY-FTST","account":[],"subaccount": [],"volume":{"fraction":0,"digits":15000},"price":{"fraction":0,"digits":1}, "instrument":"USD","type":"crypto","from":[],"to":[]}]}

BPE JSON

Retrieve All History from Process 288117946539000:

curl -X GET http://localhost:8005/rest/kvs/0/bpe/hist/288117946539000 {"\/bpe\/hist\/288117946539000":[{"id":{"id":0,"proc":"288117946539000"}, "container":"feed","feed_id":[],"prev":[],"next":[],"name":[],"task":"Created", "docs":[],"time":{"time":"{{2019,10,5},{21,21,44}}"}},{"id":{"id":1,"proc": "288117946539000"},"container":"feed","feed_id":[],"prev":[],"next":[], "name":[],"task":"Init","docs":[],"time":{"time":"{{2019,10,5},{21,21,50}}"}}, {"id":{"id":2,"proc":"288117946539000"},"container":"feed","feed_id":[], "prev":[],"next":[],"name":[],"task":"Upload","docs":[],"time":{"time": "{{2019,10,5},{21,21,51}}"}},{"id":{"id":3,"proc":"288117946539000"}, "container":"feed","feed_id":[],"prev":[],"next":[],"name":[],"task": "Payment","docs":[],"time":{"time":"{{2019,10,5},{21,21,51}}"}}]}

Retrieve Step 2 from process 288117946539000:

curl -X GET localhost:8005/rest/kvs/1/step,0,288117946539000/bpe/hist/288117946539000 {"id":{"id":2,"proc":"288117946539000"},"container":"feed","feed_id":[], "prev":[],"next":[],"name":[],"task":"Upload","docs":[],"time": {"time":"{{2019,10,5},{21,21,51}}"}}

Retrieve all processes:

$ curl -X GET http://localhost:8005/rest/kvs/0/bpe/proc {"\/bpe\/proc":[{"id":"288117946539000","container":"feed","feed_id":[], "prev":[],"next":[],"name":"IBAN Account","feeds":[],"roles":[],"tasks": [{"name":"Created","module":"bpe_account","prompt":[],"etc":[]},{"name": "Init","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name": "Upload","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name": "Signatory","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name": "Payment","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name": "Process","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name": "Final","module":"bpe_account","prompt":[],"etc":[]}],"events":[{"name": "PaymentReceived","module":[],"prompt":[],"etc":[],"payload":[],"timeout":[]}, {"name":"*","module":[],"prompt":[],"etc":[],"payload":[],"timeout": {"spec":"{0,{10,0,10}}"},"timeDate":[],"timeDuration":[],"timeCycle":[]}], "hist":[],"flows":[{"name":[],"condition":[],"source":"Created","target": "Init"},{"name":[],"condition":[],"source":"Init","target":"Upload"}, {"name":[],"condition":[],"source":"Upload","target":"Payment"}, {"name":[],"condition":[],"source":"Payment","target":["Signatory", "Process"]},{"name":[],"condition":[],"source":"Process","target": ["Process","Final"]},{"name":[],"condition":[],"source":"Signatory", "target":["Process","Final"]}],"rules":[],"docs":[],"options":[], "task":"Created","timer":[],"notifications":"undefined","result":[], "started":{"time":"{{2019,10,5},{22,5,20}}"},"beginEvent":"Created", "endEvent":"Final"}]}

MODULES

Module rest is an Erlang/OTP application, while rest_cowboy and rest_kvs are the access/routing/gate/plugin-modules to other systems.

CREDTIS