|
@@ -1,110 +0,0 @@
|
|
-<!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://tonpa.guru/blank.css?v=2" />
|
|
|
|
-</head>
|
|
|
|
-<body>
|
|
|
|
-<nav>
|
|
|
|
- <a href="https://n2o.dev/ua/">DEV</a>
|
|
|
|
- <a href="#" style="background:#ededed;">REST</a>
|
|
|
|
- <a href="#" style="background:#ededed;">UA</a>
|
|
|
|
- <a href="../../index.html">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>СИНОПСИС</h3>
|
|
|
|
- <div>REST: фреймворк з типізованим JSON<br /><br />
|
|
|
|
- <b>Переваги та цілі</b><br /><br />
|
|
|
|
- 1. Найшвидші можливі Record <-> Proplists перетворення<br />
|
|
|
|
- 2. Найменший REST фреймворк у світі<br />
|
|
|
|
- 3. ETS/KVS/Будь-яка база даних, просте налаштування<br /><br />
|
|
|
|
- Ми досягли першої мети, визначаючи генерацію коду parse_transform для перетворень кортежів.
|
|
|
|
- Друга вимога була досягнута за допомогою виключення з кодової бази фреймворка зайвого роутингу та інших сумнівних моментів.
|
|
|
|
- </div>
|
|
|
|
- </section>
|
|
|
|
-
|
|
|
|
- <section>
|
|
|
|
- <a name="usage"></a><h3>ВИКОРИСТАННЯ</h3>
|
|
|
|
- <div>Просто підключіть кінцеву точку REST безпосередньо до вашого Cowboy роутера:</div>
|
|
|
|
- <figure>
|
|
|
|
- <code>
|
|
|
|
- {"/rest/:resource", rest_cowboy, []},
|
|
|
|
- {"/rest/:resource/:id", rest_cowboy, []},
|
|
|
|
- </code>
|
|
|
|
- </figure>
|
|
|
|
- <div>
|
|
|
|
- OCT 2018 © <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="module"></a><h3>Модуль</h3>
|
|
|
|
- <p>
|
|
|
|
- Приклад реалізації REST API:
|
|
|
|
- </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>
|
|
|
|
- <a name="usage2"></a><h3>Використання API</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>
|
|
|
|
-
|
|
|
|
- <section>
|
|
|
|
- <a name="modules"></a><h3>Модулі</h3>
|
|
|
|
- <ul><li><b><a href="rest.htm">rest</a></b> — rest</li>
|
|
|
|
- <li><b><a href="rest_app.htm">rest_app</a></b> — rest_app</li>
|
|
|
|
- <li><b><a href="rest_cowboy.htm">rest_cowboy</a></b> — rest_cowboy</li>
|
|
|
|
- <li><b><a href="rest_sup.htm">rest_sup</a></b> — rest_sup</li>
|
|
|
|
- </ul>
|
|
|
|
- </section>
|
|
|
|
-
|
|
|
|
- <section>
|
|
|
|
- <a name="credits"></a><h3>Credits</h3>
|
|
|
|
- <ul><li>Dmitry Bushmelev</li></ul>
|
|
|
|
- </section>
|
|
|
|
-</main>
|
|
|
|
-<footer>
|
|
|
|
- Made with <span class="heart">❤</span> to Erlang
|
|
|
|
-</footer>
|
|
|
|
-</body>
|
|
|
|
-</html>
|
|
|