Class: Hanami::API
- Inherits:
-
Object
- Object
- Hanami::API
- Defined in:
- lib/hanami/api.rb,
lib/hanami/api/error.rb,
lib/hanami/api/router.rb,
lib/hanami/api/version.rb,
lib/hanami/api/middleware.rb,
lib/hanami/api/block/context.rb,
lib/hanami/api/middleware/app.rb,
lib/hanami/api/middleware/node.rb,
lib/hanami/api/middleware/trie.rb
Overview
Hanami::API
Defined Under Namespace
Modules: Block, Middleware Classes: Error, Router
Constant Summary collapse
- VERSION =
"0.1.1"
Class Attribute Summary collapse
- .router ⇒ Object readonly private
Class Method Summary collapse
-
.delete(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts DELETE requests for the given path.
-
.get(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts GET requests for the given path.
- .inherited(app) ⇒ Object private
-
.link(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts LINK requests for the given path.
-
.mount(*args, **kwargs, &blk) ⇒ Object
Mount a Rack application at the specified path.
-
.options(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts OPTIONS requests for the given path.
-
.patch(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts PATCH requests for the given path.
-
.post(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts POST requests for the given path.
-
.put(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts PUT requests for the given path.
-
.redirect(*args, **kwargs, &blk) ⇒ Object
Defines a route that redirects the incoming request to another path.
-
.root(*args, **kwargs, &blk) ⇒ Object
Defines a named root route (a GET route for “/”).
-
.scope(*args, **kwargs, &blk) ⇒ Object
Defines a routing scope.
-
.trace(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts TRACE requests for the given path.
-
.unlink(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts UNLINK requests for the given path.
-
.use(middleware, *args, &blk) ⇒ Object
Use a Rack middleware.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #freeze ⇒ Object
-
#initialize(router: self.class.router) ⇒ API
constructor
A new instance of API.
-
#path(name, variables = {}) ⇒ Object
private
TODO: verify if needed here on in block context.
-
#url(name, variables = {}) ⇒ Object
private
TODO: verify if needed here on in block context.
Constructor Details
#initialize(router: self.class.router) ⇒ API
Returns a new instance of API.
296 297 298 299 300 |
# File 'lib/hanami/api.rb', line 296 def initialize(router: self.class.router) @router = router freeze end |
Class Attribute Details
.router ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/hanami/api.rb', line 26 def router @router end |
Class Method Details
.delete(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts DELETE requests for the given path.
150 151 152 |
# File 'lib/hanami/api.rb', line 150 def self.delete(*args, **kwargs, &blk) @router.delete(*args, **kwargs, &blk) end |
.get(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts GET requests for the given path. It also defines a route to accept HEAD requests.
90 91 92 |
# File 'lib/hanami/api.rb', line 90 def self.get(*args, **kwargs, &blk) @router.get(*args, **kwargs, &blk) end |
.inherited(app) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 19 20 21 |
# File 'lib/hanami/api.rb', line 15 def self.inherited(app) super app.class_eval do @router = Router.new end end |
.link(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts LINK requests for the given path.
195 196 197 |
# File 'lib/hanami/api.rb', line 195 def self.link(*args, **kwargs, &blk) @router.link(*args, **kwargs, &blk) end |
.mount(*args, **kwargs, &blk) ⇒ Object
Mount a Rack application at the specified path. All the requests starting with the specified path, will be forwarded to the given application.
All the other methods (eg ‘#get`) support callable objects, but they restrict the range of the acceptable HTTP verb. Mounting an application with #mount doesn’t apply this kind of restriction at the router level, but let the application to decide.
273 274 275 |
# File 'lib/hanami/api.rb', line 273 def self.mount(*args, **kwargs, &blk) @router.mount(*args, **kwargs, &blk) end |
.options(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts OPTIONS requests for the given path.
180 181 182 |
# File 'lib/hanami/api.rb', line 180 def self.(*args, **kwargs, &blk) @router.(*args, **kwargs, &blk) end |
.patch(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts PATCH requests for the given path.
120 121 122 |
# File 'lib/hanami/api.rb', line 120 def self.patch(*args, **kwargs, &blk) @router.patch(*args, **kwargs, &blk) end |
.post(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts POST requests for the given path.
105 106 107 |
# File 'lib/hanami/api.rb', line 105 def self.post(*args, **kwargs, &blk) @router.post(*args, **kwargs, &blk) end |
.put(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts PUT requests for the given path.
135 136 137 |
# File 'lib/hanami/api.rb', line 135 def self.put(*args, **kwargs, &blk) @router.put(*args, **kwargs, &blk) end |
.redirect(*args, **kwargs, &blk) ⇒ Object
Defines a route that redirects the incoming request to another path.
224 225 226 |
# File 'lib/hanami/api.rb', line 224 def self.redirect(*args, **kwargs, &blk) @router.redirect(*args, **kwargs, &blk) end |
.root(*args, **kwargs, &blk) ⇒ Object
Defines a named root route (a GET route for “/”)
53 54 55 |
# File 'lib/hanami/api.rb', line 53 def self.root(*args, **kwargs, &blk) @router.root(*args, **kwargs, &blk) end |
.scope(*args, **kwargs, &blk) ⇒ Object
Defines a routing scope. Routes defined in the context of a scope, inherit the given path as path prefix and as a named routes prefix.
248 249 250 |
# File 'lib/hanami/api.rb', line 248 def self.scope(*args, **kwargs, &blk) @router.scope(*args, **kwargs, &blk) end |
.trace(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts TRACE requests for the given path.
165 166 167 |
# File 'lib/hanami/api.rb', line 165 def self.trace(*args, **kwargs, &blk) @router.trace(*args, **kwargs, &blk) end |
.unlink(*args, **kwargs, &blk) ⇒ Object
Defines a route that accepts UNLINK requests for the given path.
210 211 212 |
# File 'lib/hanami/api.rb', line 210 def self.unlink(*args, **kwargs, &blk) @router.unlink(*args, **kwargs, &blk) end |
.use(middleware, *args, &blk) ⇒ Object
Use a Rack middleware
291 292 293 |
# File 'lib/hanami/api.rb', line 291 def self.use(middleware, *args, &blk) @router.use(middleware, *args, &blk) end |
Instance Method Details
#call(env) ⇒ Object
314 315 316 |
# File 'lib/hanami/api.rb', line 314 def call(env) @app.call(env) end |
#freeze ⇒ Object
303 304 305 306 307 308 309 310 311 |
# File 'lib/hanami/api.rb', line 303 def freeze @app = @router.to_rack_app @url_helpers = @router.url_helpers @router.remove_instance_variable(:@url_helpers) remove_instance_variable(:@router) @url_helpers.freeze @app.freeze super end |
#path(name, variables = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: verify if needed here on in block context
322 323 324 |
# File 'lib/hanami/api.rb', line 322 def path(name, variables = {}) @url_helpers.path(name, variables) end |
#url(name, variables = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: verify if needed here on in block context
330 331 332 |
# File 'lib/hanami/api.rb', line 330 def url(name, variables = {}) @url_helpers.url(name, variables) end |