-
Notifications
You must be signed in to change notification settings - Fork 16
/
annotations.cr
135 lines (128 loc) · 4.16 KB
/
annotations.cr
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
module Athena::Routing
# Defines a `GET` endpoint.
#
# A corresponding `HEAD` endpoint is also defined.
#
# ## Fields
# * path : `String` - The path for the endpoint, may also be provided as the first positional argument.
# * constraints : `Hash(String, Regex)` - A mapping between a route's path parameters and its constraints.
#
# ## Example
# ```
# @[ART::Get(path: "/users/:id")]
# def get_user(id : Int32) : Nil
# end
# ```
annotation Get; end
# Defines a `POST` endpoint.
#
# ## Fields
# * path : `String` - The path for the endpoint, may also be provided as the first positional argument.
# * constraints : `Hash(String, Regex)` - A mapping between a route's path parameters and its constraints.
#
# ## Example
# ```
# @[ART::Post(path: "/users")]
# def new_user : Nil
# end
# ```
annotation Post; end
# Defines a `PUT` endpoint.
#
# ## Fields
# * path : `String` - The path for the endpoint, may also be provided as the first positional argument.
# * constraints : `Hash(String, Regex)` - A mapping between a route's path parameters and its constraints.
#
# ## Example
# ```
# @[ART::Put(path: "/users/:id")]
# def update_user(id : Int32) : Nil
# end
# ```
annotation Put; end
# Defines a `PATCH` endpoint.
#
# ## Fields
# * path : `String` - The path for the endpoint, may also be provided as the first positional argument.
# * constraints : `Hash(String, Regex)` - A mapping between a route's path parameters and its constraints.
#
# ## Example
# ```
# @[ART::Patch(path: "/users/:id")]
# def partial_update_user(id : Int32) : Nil
# end
# ```
annotation Patch; end
# Defines a `DELETE` endpoint.
#
# ## Fields
# * path : `String` - The path for the endpoint, may also be provided as the first positional argument.
# * constraints : `Hash(String, Regex)` - A mapping between a route's path parameters and its constraints.
#
# ## Example
# ```
# @[ART::Delete(path: "/users/:id")]
# def delete_user(id : Int32) : Nil
# end
# ```
annotation Delete; end
# Applies an `ART::ParamConverterInterface` to a given argument.
#
# See `ART::ParamConverterInterface` for more information on defining a param converter.
#
# ## Fields
#
# * name : `String` - The name of the argument that should be converted, may also be provided as the first positional argument.
# * converter : `ART::ParamConverterInterface.class` - The `ART::ParamConverterInterface` that should be used to convert this argument.
#
# ## Example
#
# ```
# @[ART::Get(path: "/multiply/:num")]
# @[ART::ParamConverter("num", converter: MultiplyConverter)]
# def multiply(num : Int32) : Int32
# num
# end
# ```
annotation ParamConverter; end
# Defines a query parameter tied to a given argument.
#
# The type of the query param is derived from the type restriction of the associated controller action argument.
#
# A non-nilable type denotes it as required. If the parameter is not supplied, and no default value is assigned, an `ART::Exceptions::BadRequest` exception is raised.
# A nilable type denotes it as optional. If the parameter is not supplied (or could not be converted), and no default value is assigned, it is `nil`.
#
# ## Fields
#
# * name : `String` - The name of the query parameter, may also be provided as the first positional argument.
# * constraints : `Regex` - A pattern the query param must match to be considered valid.
#
# ## Example
#
# ```
# @[ART::Get(path: "/example")]
# @[ART::QueryParam("query_param")]
# def get_user(query_param : String) : Nil
# end
# ```
annotation QueryParam; end
# Apply a *prefix* to all actions within `self`. Can be a static string, but may also contain path arguments.
#
# ## Fields
#
# * prefix : `String` - The path prefix to use, may also be provided as the first positional argument.
#
# ## Example
#
# ```
# @[ART::Prefix(prefix: "calendar")]
# class CalendarController < ART::Controller
# # The route of this action would be `GET /calendar/events`.
# @[ART::Get(path: "events")]
# def events : String
# "events"
# end
# end
# ```
annotation Prefix; end
end