index.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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://synrc.space/images/Synrc Neo.svg?v=1" /></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. OCT 2019 © <a href="https://github.com/5HT">5HT</a> <a href="https://5ht.co/license.htm">ISC</a><br />
  49. VER 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. <a name="kvs"></a><h3>KVS JSON</h3>
  89. <p>Automatik chain-oriented API service implementation:</p>
  90. <figure><code>
  91. $ curl -X GET http://localhost:8005/rest/kvs/0/erp/group
  92. {"\/erp\/group":[{"name":"Quanterall","url":"quanterall.com",
  93. "location":[],"type":[]}]}
  94. </code></figure>
  95. <figure><code>
  96. $ curl -i -X GET http://localhost:8005/rest/kvs/0/plm/FinaTech-Stamps/income
  97. HTTP/1.1 200 OK
  98. content-length: 1718
  99. content-type: application/json
  100. date: Fri, 04 Oct 2019 15:58:16 GMT
  101. server: Cowboy
  102. {"\/plm\/FinaTech-Stamps\/income":[{"invoice":"APR-2018-PAY-FTST","account":[],
  103. "subaccount":[],"volume":{"fraction":0,"digits":12000},"price":{"fraction":0,
  104. "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice":
  105. "AUG-2018-PAY-FTST","account":[],"subaccount":[],"volume":{"fraction":0,
  106. "digits":12000},"price":{"fraction":0,"digits":1},"instrument":"USD","type":
  107. "crypto","from":[],"to":[]},{"invoice":"FEB-2018-PAY-FTST","account":[],
  108. "subaccount":[],"volume":{"fraction":0,"digits":7000},"price":{"fraction":0,
  109. "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice":
  110. "JAN-2018-PAY-FTST","account":[],"subaccount":[],"volume":{"fraction":0,"digits":
  111. 5000},"price":{"fraction":0,"digits":1},"instrument":"USD","type":"crypto","from":
  112. [],"to":[]},{"invoice":"JUL-2018-PAY-FTST","account":[],"subaccount":[],"volume":
  113. {"fraction":0,"digits":10000},"price":{"fraction":0,"digits":1},"instrument":
  114. "USD","type":"crypto","from":[],"to":[]},{"invoice":"JUN-2018-PAY-FTST",
  115. "account":[],"subaccount":[],"volume":{"fraction":0,"digits":10000},"price":
  116. {"fraction":0,"digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},
  117. {"invoice":"MAR-2018-PAY-FTST","account":[],"subaccount":[],"volume":
  118. {"fraction":0,"digits":10000},"price":{"fraction":0,"digits":1},"instrument":
  119. "USD","type":"crypto","from":[],"to":[]},{"invoice":"MAY-2018-PAY-FTST",
  120. "account":[],"subaccount":[],"volume":{"fraction":0,"digits":15000},
  121. "price":{"fraction":0,"digits":1},"instrument":"USD","type":"crypto",
  122. "from":[],"to":[]},{"invoice":"SEP-2018-PAY-FTST","account":[],"subaccount":
  123. [],"volume":{"fraction":0,"digits":15000},"price":{"fraction":0,"digits":1},
  124. "instrument":"USD","type":"crypto","from":[],"to":[]}]}
  125. </code></figure>
  126. </section>
  127. <section>
  128. <h3>MODULES</h3>
  129. <ul><li><b><a href="man/rest.htm">rest</a></b> — rest</li>
  130. <li><b><a href="man/rest_cowboy.htm">rest_cowboy</a></b> — rest_cowboy</li>
  131. <li><b><a href="man/rest_kvs.htm">rest_kvs</a></b> — rest_kvs</li>
  132. </ul>
  133. </section>
  134. <section>
  135. <a name="credits"></a><h3>CREDTIS</h3>
  136. <ul><li>Dmitry Bushmelev</li>
  137. <li>Maxim Sokhatsky</li>
  138. </ul>
  139. </section>
  140. </main>
  141. <footer>
  142. Made with <span class="heart">❤</span> to Erlang
  143. </footer>
  144. </body>
  145. </html>