Leptus是一个运行于Cowboy框架之上的ErlangREST框架。Leptus的目的是让我们便捷地创建RESTfulAPI。
要求:
Erlang/OTPR15Bornewer
cowboy
jiffyorjsx
msgpack
示例代码:
-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 = leptus_req:param(Req, name), Body = [{<<"say">>, <<"Hi">>}, {<<"to">>, Name}], {Status, {json, Body}, State}.terminate(_Reason, _Route, _Req, _State) -> ok.
评论