A mini RESTful API framework built on cowboy and swagger
-module(example).
-export([rest_api/0]).
-export([hello/1]).
-spec(rest_api() -> [{Path :: string(), Metadata :: map()}]).
rest_api() ->
Path = "/hello",
Metadata = #{
get =>
#{tags => ["example"],
description => "hello world",
operationId => hello,
responses =>
#{<<"200">> =>
#{content =>
#{'text/plain' =>
#{schema => #{type => string}}}}}}},
[{Path, Metadata}].
hello(_Request) ->
StatusCode = 200,
Headers = #{<<"Content-Type">> => <<"text/plain">>},
Body = <<"hello world !">>,
{StatusCode, Headers, Body}.
application:ensure_all_started(minirest).
Options = #{port => 8088, modules => [example_hello_api]}.
minirest:start(?MODULE, Options).
See detail by example/example_server
-
Request filter
query & headers
-
Parameters check
-
Test suite