index.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <meta name="description" content="" />
  8. <meta name="author" content="Maxim Sokhatsky" />
  9. <title>REST</title>
  10. <link rel="stylesheet" href="https://n2o.dev/blank.css" />
  11. <link rel="stylesheet" href="https://n2o.dev/zima.css" />
  12. </head>
  13. <body>
  14. <nav>
  15. <a href="https://n2o.dev">DEV</a>
  16. <a href="#" style="background:#ededed;">REST</a>
  17. <a href="https://n2o.dev/deps/rest/man/ua/index.html">UA</a>
  18. <a href="#" style="background:#ededed;">EN</a>
  19. </nav>
  20. <header>
  21. <a href="https://github.com/synrc/rest"><img src="https://openmoji.org/data/color/svg/2615.svg" /></a>
  22. <h1>REST</h1>
  23. </header>
  24. <aside>
  25. <article>
  26. <section>
  27. <h3>SYNOPSIS</h3>
  28. <div>REST is a framework with typed JSON. Features and Goals:
  29. <ul><li>Fastest possible Record &#60;-&#62; Proplists transformations</li>
  30. <li>Smallest REST framework in the world (3 files drop).</li>
  31. <li>ETS/KVS/Any storage selection by scaffolding</li></ul>
  32. We've achived first goal by providing parse_transform code generation for tuple transformations.
  33. And second requirement was achieved by not including routing bullshit and other uncertain features.
  34. </div>
  35. </section>
  36. <section>
  37. <a name="usage"></a><h3>USAGE</h3>
  38. <div>Just plug REST endpoint directly to your Cowboy router in order
  39. to gain the JSON access for both in-memory ETS and persistent
  40. KVS databases:</div><br/>
  41. <figure>
  42. <code> {"/:res",rest_cowboy,[]},
  43. {"/:res/:id",rest_cowboy,[]},
  44. {"/kvs/0/[...]",rest_kvs,[]},
  45. {"/kvs/1/:id/[...]",rest_kvs,[]},</code>
  46. </figure><br/>
  47. <div>
  48. NOV 2021 © <a href="https://github.com/5HT">5HT</a> <a href="https://5ht.co/license.htm">ISC</a><br/>
  49. VER 6.11 6.1 5.10
  50. </div>
  51. </section>
  52. </article>
  53. </aside>
  54. <main>
  55. <section>
  56. <a name="ets"></a><h3>ETS JSON</h3>
  57. <p>Simple table-oriented service implementation:</p>
  58. <figure>
  59. <code>
  60. -module(users).
  61. -behaviour(rest).
  62. -compile({parse_transform, rest}).
  63. -include("users.hrl").
  64. -export([init/0, populate/1, exists/1, get/0, get/1, post/1, delete/1]).
  65. -rest_record(user).
  66. init() -> ets:new(users, [public, named_table, {keypos, #user.id}]).
  67. populate(Users) -> ets:insert(users, Users).
  68. exists(Id) -> ets:member(users, wf:to_list(Id)).
  69. get() -> ets:tab2list(users).
  70. get(Id) -> [User] = ets:lookup(users, wf:to_list(Id)), User.
  71. delete(Id) -> ets:delete(users, wf:to_list(Id)).
  72. post(#user{} = User) -> ets:insert(users, User);
  73. post(Data) -> post(from_json(Data, #user{})).
  74. </code>
  75. </figure>
  76. </section>
  77. <section>
  78. <h3>METHODS</h3>
  79. <figure><code>
  80. $ curl -i -X POST -d "id=vlad" localhost:8005/rest/users
  81. $ curl -i -X POST -d "id=doxtop" localhost:8005/rest/users
  82. $ curl -i -X GET localhost:8005/rest/users
  83. $ curl -i -X PUT -d "id=5HT" localhost:8005/rest/users/vlad
  84. $ curl -i -X GET localhost:8005/rest/users/5HT
  85. $ curl -i -X DELETE localhost:8005/rest/users/5HT
  86. </code></figure>
  87. </section>
  88. <section>
  89. <a name="kvs"></a><h3>KVS JSON</h3>
  90. <p>Automatiс chain-oriented API service implementation. Plug your Erlang HRL schema to
  91. <b>mix.exs</b></p>
  92. <figure><code>
  93. {:bpe, "~> 4.9.18"},
  94. {:erp, "~> 0.10.3"},
  95. </code></figure>
  96. <p>or <b>rebar.config</b>:</p>
  97. <figure><code>
  98. {bpe, ".*", {git, "git://github.com/synrc/bpe", {tag,"master"}}},
  99. {erp, ".*", {git, "git://github.com/erpuno/erp", {tag,"master"}}},
  100. </code></figure>
  101. </section>
  102. <section>
  103. <a name="kvs"></a><h3>ERP JSON</h3>
  104. <p>Retrieve ERP organizational structure:</p>
  105. <figure><code>
  106. $ curl -X GET http://localhost:8005/rest/kvs/0/erp/group
  107. {"\/erp\/group":[{"name":"Quanterall","url":"quanterall.com",
  108. "location":[],"type":[]}]}
  109. </code></figure>
  110. <p>Retrive all invoice payments for Stamp project of FinaTech company:</p>
  111. <figure><code>
  112. $ curl -X GET http://localhost:8005/rest/kvs/0/plm/FinaTech-Stamps/income
  113. {"\/plm\/FinaTech-Stamps\/income":[{"invoice":"APR-2018-PAY-FTST","account":[],
  114. "subaccount":[],"volume":{"fraction":0,"digits":12000},"price":{"fraction":0,
  115. "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice":
  116. "AUG-2018-PAY-FTST","account":[],"subaccount":[],"volume":{"fraction":0,
  117. "digits":12000},"price":{"fraction":0,"digits":1},"instrument":"USD","type":
  118. "crypto","from":[],"to":[]},{"invoice":"FEB-2018-PAY-FTST","account":[],
  119. "subaccount":[],"volume":{"fraction":0,"digits":7000},"price":{"fraction":0,
  120. "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice":
  121. "JAN-2018-PAY-FTST","account":[],"subaccount":[],"volume":{"fraction":0,"digits":
  122. 5000},"price":{"fraction":0,"digits":1},"instrument":"USD","type":"crypto","from":
  123. [],"to":[]},{"invoice":"JUL-2018-PAY-FTST","account":[],"subaccount":[],"volume":
  124. {"fraction":0,"digits":10000},"price":{"fraction":0,"digits":1},"instrument":
  125. "USD","type":"crypto","from":[],"to":[]},{"invoice":"JUN-2018-PAY-FTST",
  126. "account":[],"subaccount":[],"volume":{"fraction":0,"digits":10000},"price":
  127. {"fraction":0,"digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},
  128. {"invoice":"MAR-2018-PAY-FTST","account":[],"subaccount":[],"volume":
  129. {"fraction":0,"digits":10000},"price":{"fraction":0,"digits":1},"instrument":
  130. "USD","type":"crypto","from":[],"to":[]},{"invoice":"MAY-2018-PAY-FTST",
  131. "account":[],"subaccount":[],"volume":{"fraction":0,"digits":15000},
  132. "price":{"fraction":0,"digits":1},"instrument":"USD","type":"crypto",
  133. "from":[],"to":[]},{"invoice":"SEP-2018-PAY-FTST","account":[],"subaccount":
  134. [],"volume":{"fraction":0,"digits":15000},"price":{"fraction":0,"digits":1},
  135. "instrument":"USD","type":"crypto","from":[],"to":[]}]}
  136. </code></figure>
  137. </section>
  138. <section>
  139. <a name="kvs"></a><h3>BPE JSON</h3>
  140. <p>Retrieve All History from Process 288117946539000:</p>
  141. <figure><code>
  142. curl -X GET http://localhost:8005/rest/kvs/0/bpe/hist/288117946539000
  143. {"\/bpe\/hist\/288117946539000":[{"id":{"id":0,"proc":"288117946539000"},
  144. "container":"feed","feed_id":[],"prev":[],"next":[],"name":[],"task":"Created",
  145. "docs":[],"time":{"time":"{{2019,10,5},{21,21,44}}"}},{"id":{"id":1,"proc":
  146. "288117946539000"},"container":"feed","feed_id":[],"prev":[],"next":[],
  147. "name":[],"task":"Init","docs":[],"time":{"time":"{{2019,10,5},{21,21,50}}"}},
  148. {"id":{"id":2,"proc":"288117946539000"},"container":"feed","feed_id":[],
  149. "prev":[],"next":[],"name":[],"task":"Upload","docs":[],"time":{"time":
  150. "{{2019,10,5},{21,21,51}}"}},{"id":{"id":3,"proc":"288117946539000"},
  151. "container":"feed","feed_id":[],"prev":[],"next":[],"name":[],"task":
  152. "Payment","docs":[],"time":{"time":"{{2019,10,5},{21,21,51}}"}}]}
  153. </code></figure>
  154. <p>Retrieve Step 2 from process 288117946539000:</p>
  155. <figure><code>
  156. curl -X GET localhost:8005/rest/kvs/1/step,0,288117946539000/bpe/hist/288117946539000
  157. {"id":{"id":2,"proc":"288117946539000"},"container":"feed","feed_id":[],
  158. "prev":[],"next":[],"name":[],"task":"Upload","docs":[],"time":
  159. {"time":"{{2019,10,5},{21,21,51}}"}}
  160. </code></figure>
  161. <p>Retrieve all processes:</p>
  162. <figure><code>
  163. $ curl -X GET http://localhost:8005/rest/kvs/0/bpe/proc
  164. {"\/bpe\/proc":[{"id":"288117946539000","container":"feed","feed_id":[],
  165. "prev":[],"next":[],"name":"IBAN Account","feeds":[],"roles":[],"tasks":
  166. [{"name":"Created","module":"bpe_account","prompt":[],"etc":[]},{"name":
  167. "Init","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name":
  168. "Upload","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name":
  169. "Signatory","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name":
  170. "Payment","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name":
  171. "Process","module":"bpe_account","prompt":[],"roles":[],"etc":[]},{"name":
  172. "Final","module":"bpe_account","prompt":[],"etc":[]}],"events":[{"name":
  173. "PaymentReceived","module":[],"prompt":[],"etc":[],"payload":[],"timeout":[]},
  174. {"name":"*","module":[],"prompt":[],"etc":[],"payload":[],"timeout":
  175. {"spec":"{0,{10,0,10}}"},"timeDate":[],"timeDuration":[],"timeCycle":[]}],
  176. "hist":[],"flows":[{"name":[],"condition":[],"source":"Created","target":
  177. "Init"},{"name":[],"condition":[],"source":"Init","target":"Upload"},
  178. {"name":[],"condition":[],"source":"Upload","target":"Payment"},
  179. {"name":[],"condition":[],"source":"Payment","target":["Signatory",
  180. "Process"]},{"name":[],"condition":[],"source":"Process","target":
  181. ["Process","Final"]},{"name":[],"condition":[],"source":"Signatory",
  182. "target":["Process","Final"]}],"rules":[],"docs":[],"options":[],
  183. "task":"Created","timer":[],"notifications":"undefined","result":[],
  184. "started":{"time":"{{2019,10,5},{22,5,20}}"},"beginEvent":"Created",
  185. "endEvent":"Final"}]}
  186. </code></figure>
  187. </section>
  188. <section>
  189. <h3>MODULES</h3>
  190. <p>Module <b>rest</b> is an Erlang/OTP application, while
  191. <b>rest_cowboy</b> and <b>rest_kvs</b> are the access/routing/gate/plugin-modules
  192. to other systems.</p>
  193. <ul><li><b><a href="man/rest.htm">rest</a></b> — rest</li>
  194. <li><b><a href="man/rest_cowboy.htm">rest_cowboy</a></b> — rest_cowboy</li>
  195. <li><b><a href="man/rest_kvs.htm">rest_kvs</a></b> — rest_kvs</li></ul>
  196. </section>
  197. <section>
  198. <a name="credits"></a><h3>CREDTIS</h3>
  199. <ul><li>Dmitry Bushmelev</li>
  200. <li>Maxim Sokhatsky</li></ul>
  201. </section>
  202. </main>
  203. <footer>
  204. Made with <span class="heart">❤</span> to Erlang
  205. </footer>
  206. </body>
  207. </html>