Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pkoretic/recurse-router
A routing middleware for the recurse web framework
https://github.com/pkoretic/recurse-router
Last synced: 6 days ago
JSON representation
A routing middleware for the recurse web framework
- Host: GitHub
- URL: https://github.com/pkoretic/recurse-router
- Owner: pkoretic
- License: mit
- Created: 2015-07-24T12:35:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-24T14:38:13.000Z (about 8 years ago)
- Last Synced: 2024-04-14T22:56:01.495Z (7 months ago)
- Language: C++
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#Router
[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/xwalk/recurse-router/blob/master/LICENSE)
Recurse router middleware
Supports:
* GET
* PUT
* POST
* PATCH
* DELETE
* HEAD
* OPTIONS
* ALL - matches all routes### Example
```
#include "router.hpp"int main(int argc, char *argv[])
{
Recurse app(argc, argv);Module::Router router;
router.GET("/hello/:user", [](auto &ctx, auto /* next */)
{
ctx.response.send("Hello World " + ctx.request.getParam("user"));
});app.listen();
}
```### Parameters
Parameters are saved in QHash `params` property inside **Recurse** `Request` class.
To fetch values use `Request::getParam(key)` helper function:```
ctx.request.getParam("name")
```Standard, required params:
```
#include "router.hpp"int main(int argc, char *argv[])
{
Recurse app(argc, argv);Module::Router router;
// matches /hello/john
router.GET("/hello/:name", [](auto &ctx, auto /* next */)
{
ctx.response.send("hello world " + ctx.request.getParam("name");
});app.listen();
}```
Optional params
```
// matches both /hi and /hi/johnny requests
router.GET("/hi/:user?", [](auto &ctx, auto /* next */)
{
ctx.response.send("hi " + ctx.request.getParam("name");
});
```Universal, catch-all parameter
```
// matches all GET calls (those that are not catched before hand)
router.GET("*", [](auto &ctx, auto /* next */)
{
ctx.response.send("hi all");
});```
catch-all with Router.ALL, matches everything
```
// matches all calls (those that are not catched before hand)
router.ALL("*", [](auto &ctx, auto /* next */)
{
ctx.response.send("all matched, all catched");
});```