index.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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://synrc.space/synrc.css" />
  11. </head>
  12. <body>
  13. <nav>
  14. <a href="https://n2o.dev">DEV</a>
  15. <a href="#" style="background:#ededed;">REST</a>
  16. <a href="https://n2o.dev/deps/rest/man/ua/index.html">UA</a>
  17. <a href="#" style="background:#ededed;">EN</a>
  18. </nav>
  19. <header>
  20. <a href="https://github.com/synrc/rest"><img src="https://synrc.space/images/Synrc Neo.svg?v=1" /></a>
  21. <h1>REST</h1>
  22. </header>
  23. <aside>
  24. <article>
  25. <section>
  26. <h3>SYNOPSIS</h3>
  27. <div>REST: framework with typed JSON<br /><br />
  28. <b>Features and Goals</b><br /><br />
  29. 1. Fastest possible Record &#60;-&#62; Proplists transformations<br />
  30. 2. Smallest REST framework in the world<br />
  31. 3. ETS/KVS/Any storage selection by scaffolding<br /><br />
  32. We&#39;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:</div>
  39. <figure>
  40. <code>
  41. {"/rest/:resource", rest_cowboy, []},
  42. {"/rest/:resource/:id", rest_cowboy, []},
  43. </code>
  44. </figure>
  45. <div>
  46. OCT 2018 © <a href="https://github.com/5HT">5HT</a> <a href="https://5ht.co/license.htm">ISC</a><br />
  47. VER 5.10
  48. </div>
  49. </section>
  50. </article>
  51. </aside>
  52. <main>
  53. <section>
  54. <a name="module"></a><h3>Module</h3>
  55. <p>
  56. Sample REST service implementation:
  57. </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. <a name="usage2"></a><h3>Usage</h3>
  79. <figure>
  80. <code>
  81. $ curl -i -X POST -d "id=vlad" localhost:8005/rest/users
  82. $ curl -i -X POST -d "id=doxtop" localhost:8005/rest/users
  83. $ curl -i -X GET localhost:8005/rest/users
  84. $ curl -i -X PUT -d "id=5HT" localhost:8005/rest/users/vlad
  85. $ curl -i -X GET localhost:8005/rest/users/5HT
  86. $ curl -i -X DELETE localhost:8005/rest/users/5HT
  87. </code></figure>
  88. </section>
  89. <section>
  90. <a name="modules"></a><h3>Modules</h3>
  91. <ul><li><b><a href="man/rest.htm">rest</a></b> — rest</li>
  92. <li><b><a href="man/rest_app.htm">rest_app</a></b> — rest_app</li>
  93. <li><b><a href="man/rest_cowboy.htm">rest_cowboy</a></b> — rest_cowboy</li>
  94. <li><b><a href="man/rest_sup.htm">rest_sup</a></b> — rest_sup</li>
  95. </ul>
  96. </section>
  97. <section>
  98. <a name="credits"></a><h3>Credits</h3>
  99. <ul><li>Dmitry Bushmelev</li></ul>
  100. </section>
  101. </main>
  102. <footer>
  103. Made with <span class="heart">❤</span> to Erlang
  104. </footer>
  105. </body>
  106. </html>