123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta name="description" content="" />
- <meta name="author" content="Maxim Sokhatsky" />
- <title>REST</title>
- <link rel="stylesheet" href="https://n2o.dev/blank.css" />
- <link rel="stylesheet" href="https://n2o.dev/zima.css" />
- </head>
- <body>
- <nav>
- <a href="https://n2o.dev">DEV</a>
- <a href="#" style="background:#ededed;">REST</a>
- <a href="https://n2o.dev/deps/rest/man/ua/index.html">UA</a>
- <a href="#" style="background:#ededed;">EN</a>
- </nav>
- <header>
- <a href="https://github.com/synrc/rest"><img src="https://synrc.space/images/Synrc Neo.svg?v=1" /></a>
- <h1>REST</h1>
- </header>
- <aside>
- <article>
- <section>
- <h3>SYNOPSIS</h3>
- <div>REST is a framework with typed JSON. Features and Goals:
- <ul><li>Fastest possible Record <-> Proplists transformations</li>
- <li>Smallest REST framework in the world (3 files drop).</li>
- <li>ETS/KVS/Any storage selection by scaffolding</li></ul>
- We've achived first goal by providing parse_transform code generation for tuple transformations.
- And second requirement was achieved by not including routing bullshit and other uncertain features.
- </div>
- </section>
- <section>
- <a name="usage"></a><h3>USAGE</h3>
- <div>Just plug REST endpoint directly to your Cowboy router in order
- to gain the JSON access for both in-memory ETS and persistent
- KVS databases:</div><br/>
- <figure>
- <code> {"/:res",rest_cowboy,[]},
- {"/:res/:id",rest_cowboy,[]},
- {"/kvs/0/[...]",rest_kvs,[]},
- {"/kvs/1/:id/[...]",rest_kvs,[]},</code>
- </figure><br/>
- <div>
- OCT 2019 © <a href="https://github.com/5HT">5HT</a> <a href="https://5ht.co/license.htm">ISC</a><br />
- VER 5.10
- </div>
- </section>
- </article>
- </aside>
- <main>
- <section>
- <a name="ets"></a><h3>ETS JSON</h3>
- <p>Simple table-oriented service implementation:</p>
- <figure>
- <code>
- -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{})).
- </code>
- </figure>
- </section>
- <section>
- <h3>METHODS</h3>
- <figure><code>
- $ 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
- </code></figure>
- <section>
- <a name="kvs"></a><h3>KVS JSON</h3>
- <p>Automatik chain-oriented API service implementation:</p>
- <figure><code>
- $ curl -X GET http://localhost:8005/rest/kvs/0/erp/group
- {"\/erp\/group":[{"name":"Quanterall","url":"quanterall.com",
- "location":[],"type":[]}]}
- </code></figure>
- <figure><code>
- $ curl -i -X GET http://localhost:8005/rest/kvs/0/plm/FinaTech-Stamps/income
- HTTP/1.1 200 OK
- content-length: 1718
- content-type: application/json
- date: Fri, 04 Oct 2019 15:58:16 GMT
- server: Cowboy
- {"\/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":[]}]}
- </code></figure>
- </section>
- <section>
- <h3>MODULES</h3>
- <ul><li><b><a href="man/rest.htm">rest</a></b> — rest</li>
- <li><b><a href="man/rest_cowboy.htm">rest_cowboy</a></b> — rest_cowboy</li>
- <li><b><a href="man/rest_kvs.htm">rest_kvs</a></b> — rest_kvs</li>
- </ul>
- </section>
- <section>
- <a name="credits"></a><h3>CREDTIS</h3>
- <ul><li>Dmitry Bushmelev</li>
- <li>Maxim Sokhatsky</li>
- </ul>
- </section>
- </main>
- <footer>
- Made with <span class="heart">❤</span> to Erlang
- </footer>
- </body>
- </html>
|