leptus icon indicating copy to clipboard operation
leptus copied to clipboard

The Erlang REST framework

  • Leptus

    Leptus is an Erlang REST framework that runs on top of Cowboy web server.

    Leptus simplifies creating RESTful APIs in Erlang.

** Requirements

  • Erlang/OTP 18 or newer
  • [[https://github.com/ninenines/cowboy][Cowboy 2.4.0]]
  • [[https://github.com/davisp/jiffy][Jiffy 0.15.2]]

** Installation

Clone it, and run ~make~. Or add it to your rebar configuration.

#+BEGIN_SRC erlang {deps, [ {leptus, ".*", {git, "git://github.com/sinasamavati/leptus.git", {branch, "master"}}} ]}. #+END_SRC

** Quick Example

#+BEGIN_SRC erlang -module(hello). -compile({parse_transform, leptus_pt}).

%% leptus callbacks -export([init/3]). -export([get/3]). -export([terminate/4]).

init(_Route, _Req, State) -> {ok, State}.

get("/", _Req, State) -> {<<"Hello, leptus!">>, State}; get("/hi/:name", Req, State) -> Status = ok, Name = cowboy_req:binding(name, Req), Body = #{<<"say">> => <<"Hi">>, <<"to">> => Name}, {Status, Body, State}.

terminate(_Reason, _Route, _Req, _State) -> ok. #+END_SRC

#+BEGIN_SRC $ erl -pa ebin deps/*/ebin #+END_SRC

#+BEGIN_SRC erlang 1> c(hello). 2> leptus:start_listener(http, [{'_', [{hello, undefined_state}]}]). Leptus started on http://127.0.0.1:8080 #+END_SRC

#+BEGIN_SRC $ curl localhost:8080/hi/Leptus {"say":"Hi","to":"Leptus"} #+END_SRC

** Features

  • Supports ~GET~, ~PUT~, ~POST~ and ~DELETE~ HTTP methods
  • Can respond in plain text or JSON
  • Supports basic authentication
  • Can be upgraded while it's running (no stopping is required)
  • Supports HTTPS
  • Provides a simple way for dealing with Cross-Origin Resource Sharing

** Documentation

Please refer to [[https://sinasamavati.com/leptus][https://sinasamavati.com/leptus]].

** Support

  • [[https://github.com/sinasamavati/leptus/issues][Issue tracker]]
  • #leptus IRC channel on Freenode
  • [[https://groups.google.com/group/leptus][leptus]] mailing-list on Google Groups

** License

MIT, see LICENSE file for more details.