-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsr_elements_handler.erl
55 lines (51 loc) · 1.41 KB
/
sr_elements_handler.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%%% @doc POST|GET /elements handler
-module(sr_elements_handler).
-behaviour(trails_handler).
-include_lib("mixer/include/mixer.hrl").
-mixin([{ sr_entities_handler
, [ init/3
, rest_init/2
, allowed_methods/2
, resource_exists/2
, content_types_accepted/2
, content_types_provided/2
, handle_get/2
, handle_post/2
]
}]).
-export([ trails/0
]).
-spec trails() -> trails:trails().
trails() ->
RequestBody =
#{ name => <<"request body">>
, in => body
, description => <<"request body (as json)">>
, required => true
},
Metadata =
#{ get =>
#{ tags => ["elements"]
, description => "Returns the list of elements"
, produces => ["application/json"]
}
, post =>
#{ tags => ["elements"]
, description => "Creates a new element"
, consumes => ["application/json", "application/json; charset=utf-8"]
, produces => ["application/json"]
, parameters => [RequestBody]
}
, put =>
#{ tags => ["elements"]
, description => "Updates an element"
, produces => ["application/json"]
, parameters => [RequestBody]
}
},
Path = "/elements",
Opts = #{ path => Path
, model => elements
, verbose => true
},
[trails:trail(Path, ?MODULE, Opts, Metadata)].