Class: Hanami::API
- Inherits:
-
Object
- Object
- Hanami::API
- Defined in:
- lib/hanami/api.rb,
lib/hanami/api/dsl.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
Overview
Hanami::API
Defined Under Namespace
Modules: Block, DSL, Middleware Classes: Error, Router
Constant Summary collapse
- VERSION =
"0.3.0"
Class Method Summary collapse
-
.delete ⇒ Object
Defines a route that accepts DELETE requests for the given path.
-
.get ⇒ Object
Defines a route that accepts GET requests for the given path.
-
.helpers(mod = nil, &blk) ⇒ Object
Defines helper methods available within the block context.
- .inherited(app) ⇒ Object private
-
.link ⇒ Object
Defines a route that accepts LINK requests for the given path.
-
.mount ⇒ Object
Mount a Rack application at the specified path.
-
.options ⇒ Object
Defines a route that accepts OPTIONS requests for the given path.
-
.patch ⇒ Object
Defines a route that accepts PATCH requests for the given path.
-
.post ⇒ Object
Defines a route that accepts POST requests for the given path.
-
.put ⇒ Object
Defines a route that accepts PUT requests for the given path.
-
.redirect ⇒ Object
Defines a route that redirects the incoming request to another path.
-
.root ⇒ Object
Defines a named root route (a GET route for “/”).
-
.scope ⇒ Object
Defines a routing scope.
-
.trace ⇒ Object
Defines a route that accepts TRACE requests for the given path.
-
.unlink ⇒ 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
-
#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.
Class Method Details
.delete ⇒ Object
Defines a route that accepts DELETE requests for the given path.
195 196 197 |
# File 'lib/hanami/api.rb', line 195 def self.delete(...) @router.delete(...) end |
.get ⇒ Object
Defines a route that accepts GET requests for the given path. It also defines a route to accept HEAD requests.
135 136 137 |
# File 'lib/hanami/api.rb', line 135 def self.get(...) @router.get(...) end |
.helpers(mod = nil, &blk) ⇒ Object
Defines helper methods available within the block context. Helper methods have access to default utilities available in block context (e.g. ‘#halt`).
70 71 72 |
# File 'lib/hanami/api.rb', line 70 def self.helpers(mod = nil, &blk) const_get(:BlockContext).include(mod || Module.new(&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.
16 17 18 19 20 21 |
# File 'lib/hanami/api.rb', line 16 def self.inherited(app) super app.extend(DSL::ClassMethods) app.include(DSL::InstanceMethods) end |
.link ⇒ Object
Defines a route that accepts LINK requests for the given path.
240 241 242 |
# File 'lib/hanami/api.rb', line 240 def self.link(...) @router.link(...) end |
.mount ⇒ 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.
318 319 320 |
# File 'lib/hanami/api.rb', line 318 def self.mount(...) @router.mount(...) end |
.options ⇒ Object
Defines a route that accepts OPTIONS requests for the given path.
225 226 227 |
# File 'lib/hanami/api.rb', line 225 def self.(...) @router.(...) end |
.patch ⇒ Object
Defines a route that accepts PATCH requests for the given path.
165 166 167 |
# File 'lib/hanami/api.rb', line 165 def self.patch(...) @router.patch(...) end |
.post ⇒ Object
Defines a route that accepts POST requests for the given path.
150 151 152 |
# File 'lib/hanami/api.rb', line 150 def self.post(...) @router.post(...) end |
.put ⇒ Object
Defines a route that accepts PUT requests for the given path.
180 181 182 |
# File 'lib/hanami/api.rb', line 180 def self.put(...) @router.put(...) end |
.redirect ⇒ Object
Defines a route that redirects the incoming request to another path.
269 270 271 |
# File 'lib/hanami/api.rb', line 269 def self.redirect(...) @router.redirect(...) end |
.root ⇒ Object
Defines a named root route (a GET route for “/”)
98 99 100 |
# File 'lib/hanami/api.rb', line 98 def self.root(...) @router.root(...) end |
.scope ⇒ 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.
293 294 295 |
# File 'lib/hanami/api.rb', line 293 def self.scope(...) @router.scope(...) end |
.trace ⇒ Object
Defines a route that accepts TRACE requests for the given path.
210 211 212 |
# File 'lib/hanami/api.rb', line 210 def self.trace(...) @router.trace(...) end |
.unlink ⇒ Object
Defines a route that accepts UNLINK requests for the given path.
255 256 257 |
# File 'lib/hanami/api.rb', line 255 def self.unlink(...) @router.unlink(...) end |
.use(middleware, *args, &blk) ⇒ Object
Use a Rack middleware
336 337 338 |
# File 'lib/hanami/api.rb', line 336 def self.use(middleware, *args, &blk) @router.use(middleware, *args, &blk) end |
Instance Method Details
#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
344 345 346 |
# File 'lib/hanami/api.rb', line 344 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
352 353 354 |
# File 'lib/hanami/api.rb', line 352 def url(name, variables = {}) @url_helpers.url(name, variables) end |