88 lines
2.2 KiB
Plaintext
88 lines
2.2 KiB
Plaintext
= Crow =
|
|
|
|
Crow is a fast, [[flask]]-like C++ microframework
|
|
|
|
== Apps ==
|
|
|
|
Crow provides a `crow::App` type that comes in two flavors
|
|
|
|
* `crow::SimpleApp`
|
|
* no middle ware
|
|
* `crow::App<m1, m2>`
|
|
* uses m1, m2, etc. middleware
|
|
|
|
Some other usefule interfaces
|
|
|
|
* `bindaddr(192.168.1.144)`
|
|
* takes an IP addr to bind to
|
|
* `.port(443)`
|
|
* takes an int port to listen on
|
|
* `.multithreaded()`
|
|
* enable multithreaded request handling
|
|
* `.run()`
|
|
* Run the app
|
|
* Run is blocking, use `run_async` for non blocking
|
|
|
|
== Routes ==
|
|
|
|
Routes assign URLs to function calls. To assign a route, use the macro
|
|
|
|
`CROW_ROUTE(app, url)`
|
|
|
|
where,
|
|
* `app` is the app class to assign the route to
|
|
* `url` is the relative path is assigned to the route
|
|
* paths can take paramaters
|
|
* `/hello/<int>`
|
|
* paramaters can be
|
|
* `int`
|
|
* `uint`
|
|
* `double`
|
|
* `string`
|
|
* `path`
|
|
|
|
HTTP methods can also be changed on routes via the `.method()` call, appended
|
|
to the `CROW_ROUTE` macro.
|
|
|
|
HTTP methods include
|
|
* `crow::HTTPMethod::GET`
|
|
* `crow::HTTPMethod::PATCH`
|
|
* `crow::HTTPMethod::POST`
|
|
|
|
=== Catchall route ===
|
|
|
|
By default, crow will return a 404 page for not defined routes. However the
|
|
special `CROW_CATCHALL_ROUTE(app)` macro can be used the same as other routes,
|
|
however the catchall route will be used to catch all undefined routes
|
|
|
|
== JSON ==
|
|
|
|
Crow has built in JSON support. Json values are broken into a read and write
|
|
object, `rvalue` and `wvalue`. They can take
|
|
* bool
|
|
* Number
|
|
* double
|
|
* int
|
|
* unsigned int
|
|
* std::string
|
|
* std::vector (LIST)
|
|
* Object (`crow::json::wvalue` or `crow::json::rvalue`)
|
|
|
|
`rvalue` is used for taking a JSON string and parsing it into `crow::json`. You
|
|
can only READ from a `rvalue`. To write to one, convert to `wvalue`. This is
|
|
done via `crow::json::wvalue wval(rval);`, where `rval` is the `rvalue` you
|
|
want to convert.
|
|
|
|
You can return a `wvalue` in a route handler, and the type is automatically
|
|
casted and the header Content-Type header is automatically set to
|
|
`application/json`.
|
|
|
|
== Mustache ==
|
|
|
|
See [[Mustache]]
|
|
|
|
An HTML page template with mustache tags is loaded into a
|
|
`crow::mustache::template_t`. The file needs to be in a templates directory.
|
|
These templates are read at runtime, and therefore need to be available to the
|
|
binary.
|