Module stardust.router
Ziggy Router
Functions
new () | Create a new stardust router. |
pattern (self, pattern) | Create a Lua string match match object for use with a route |
exact (self, pattern, caseless) | Create a exact match object for use with a route. |
regex (self, pattern, caseless) | Create a regex match object for use with a route |
route (self, method, pattern, func) | Add a route |
get (self, pattern, func) | Convenience function to add a route for GET |
post (self, pattern, func) | Convenience function to add a route for POST |
put (self, pattern, func) | Convenience function to add a route for PUT |
delete (self, pattern, func) | Convenience function to add a route for DELETE |
all (self, pattern, func) | Convenience function to add a route that matches all http methods |
Functions
- new ()
-
Create a new stardust router.
Returns:
-
a stardust router
- pattern (self, pattern)
-
Create a Lua string match match object for use with a route
Parameters:
- self stardust router
- pattern Lua string mattern
Returns:
-
an object usable with a route
Usage:
local r = stardust.router.new() r:get(r:pattern("/foo/(%d+)"), function(req, res) ... end) -- captures are availible in req.params -- in above, the capture is availible in r.params[1]
- exact (self, pattern, caseless)
-
Create a exact match object for use with a route. This just checks if two strings are equal
Parameters:
- self stardust router
- pattern string to match
- caseless whether to do casless match. defaults to false
Returns:
-
an object usable with a route
- regex (self, pattern, caseless)
-
Create a regex match object for use with a route
Parameters:
- self stardust router
- pattern regular expression
- caseless whether to do casless match. defaults for false
Returns:
-
an object usable with a route
Usage:
local r = stardust.router.new() r:get(r:regex("/foo/([0-9]+)"), function(req, res) ... end) -- captures are availible in req.params -- in above, the capture is availible in r.params[1] -- you can also used named captures r:get(r:regex("/foo/(?<id>[0-9]+)"), function(req, res) ... end) -- capture is availible as r.params[1] as well as r.params.id
- route (self, method, pattern, func)
-
Add a route
Parameters:
- self stardust.router
- method HTTP method, ie GET, POST. If nil, this will apply to all methods
- pattern uri pattern to match. if this is a string, it is used as a Lua string pattern. Use the results from exact, regex, pattern ,etc
- func function to call when this pattern is matched. function should take 2 arguments: stardust.request and stardust.response and return nothing on success
Returns:
-
stardust.router
self
Usage:
app = stardust.new() app:route('GET', '/foo', function(ngx, res) res.body = "hello" end)
- get (self, pattern, func)
-
Convenience function to add a route for GET
Parameters:
- self stardust application
- pattern uri pattern to match
- func function
see also:
- post (self, pattern, func)
-
Convenience function to add a route for POST
Parameters:
- self stardust application
- pattern uri pattern to match
- func function
see also:
- put (self, pattern, func)
-
Convenience function to add a route for PUT
Parameters:
- self stardust application
- pattern uri pattern to match
- func function
see also:
- delete (self, pattern, func)
-
Convenience function to add a route for DELETE
Parameters:
- self stardust application
- pattern uri pattern to match
- func function
see also:
- all (self, pattern, func)
-
Convenience function to add a route that matches all http methods
Parameters:
- self stardust application
- pattern uri pattern to match
- func function
see also: