mirror https://github.com/synrc/rest

Namdak Tonpa 32e677f193 kvs sample index.htm 5 лет назад
man 3b1a4a1dc6 zima css 5 лет назад
src c4d3d5ae5a kvs sample index.htm 5 лет назад
.travis.yml 9a4e21d50a master 6 лет назад
CNAME c9d04418ba man 6 лет назад
LICENSE f0cc284874 license 11 лет назад
README.md 06ef48df90 Update README.md 5 лет назад
index.html 32e677f193 kvs sample index.htm 5 лет назад
mix.exs 108577f99a wip 5 лет назад
rebar.config ce37be1c02 rebar.config 5 лет назад
sys.config 05ac2e68d0 sys.config 5 лет назад

README.md

REST: framework with typed JSON

Build Status Hex pm

Features and Goals

  • Fastest possibe Record <-> Proplists transformations
  • Smallest REST framework in the world
  • ETS/KVS/Any storage selection by scaffolding

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.

Usage

Just plug REST endpoint directly to your Cowboy router:

{"/rest/:resource", rest_cowboy, []},
{"/rest/:resource/:id", rest_cowboy, []},

Module

Sample REST service implementation:

-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{})).

Usage

$ 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

Credits

  • Dmitry Bushmelev

OM A HUM