而且在使用Misultin的时候对参数的处理应该怎么做?目前的做法感觉很臃肿,我该如何处理参数的异常?
handle('GET', ["datalock", "checkall"], Req) -> Args = Req:parse_qs(), case {Req:get_variable("keys", Args), Req:get_variable("user", Args), Req:get_variable("callback", Args)} of {undefined, _, _} -> Req:ok([{"Content-Type", "text/plain"}], "error param."); {_, undefined, _} -> Req:ok([{"Content-Type", "text/plain"}], "error param."); {_, _, undefined} -> Req:ok([{"Content-Type", "text/plain"}], "error param."); {Keys, User, Callback} -> case checkIds(Keys, User) of {ok, Result} -> Req:ok([{"Content-Type", "application/json;charset=utf-8"}], Callback++"("++Result++")") end end;
同样推荐 cowboy,主要是原因是 cowboy 现在几乎是行业务标准,各种框架和协议都是基于 cowboy 的。
如果喜欢用 Elixir 写 Erlang,并且用来写 API 的话,推荐 https://github.com/falood/maru 。
比较喜欢cowboy,一个比较nice的特性是支持连接池。
一个小的应用项目,riak-http
github地址
接口说明
推荐cowboy
cowboy在erlang开源项目中属于明星框架了,mochiweb的在使用方法上没有cowboy方便
mochiweb挺好的啊
elixir 用 phoenix