Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/synrc/rest
☕ REST: RFC-2616 Framework
https://github.com/synrc/rest
http json rest
Last synced: 3 days ago
JSON representation
☕ REST: RFC-2616 Framework
- Host: GitHub
- URL: https://github.com/synrc/rest
- Owner: synrc
- License: other
- Created: 2014-03-13T17:09:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-11-08T16:49:49.000Z (about 3 years ago)
- Last Synced: 2024-10-31T09:09:04.131Z (8 days ago)
- Topics: http, json, rest
- Language: Erlang
- Homepage: https://rest.n2o.dev
- Size: 148 KB
- Stars: 83
- Watchers: 9
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Erlang - Micro-REST framework with typed JSON. (Frameworks)
- fucking-awesome-elixir - rest - Micro-REST framework with typed JSON. (Frameworks)
- awesome-elixir - rest - Micro-REST framework with typed JSON. (Frameworks)
README
REST: framework with typed JSON
===============================[![Actions Status](https://github.com/synrc/rest/workflows/mix/badge.svg)](https://github.com/synrc/rest/actions)
[![Build Status](https://travis-ci.com/synrc/rest.svg?branch=master)](https://travis-ci.com/synrc/rest)
[![Hex pm](http://img.shields.io/hexpm/v/rest.svg?style=flat)](https://hex.pm/packages/rest)Features and Goals
------------------* Fastest possibe Record <-> Proplists transformations
* Smallest REST framework in the world
* ETS/KVS/Any storage selection by scaffoldingWe'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:
```erlang
{"/rest/:resource", rest_cowboy, []},
{"/rest/:resource/:id", rest_cowboy, []},
```Module
------Sample REST service implementation:
```erlang
-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
-----```sh
$ 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 — ETS
* Maxim Sokhatsky — KVSOM A HUM