Giter Site home page Giter Site logo

rest's Introduction

REST: framework with typed JSON

Actions Status 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 — ETS
  • Maxim Sokhatsky — KVS

OM A HUM

rest's People

Contributors

5ht avatar 221v avatar fnchooft avatar amrfaissal avatar rgrinberg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.