Crate rouille [−] [src]
The rouille library is very easy to get started with.
Listening to a port is done by calling the start_server
function:
use rouille::Request; use rouille::Response; rouille::start_server("0.0.0.0:1234", move |request| { Response::text("hello world") });Run
Whenever an HTTP request is received on the address passed as first parameter, the closure
passed as second parameter is called. This closure must then return a
Response
that will be sent back to the client.
Handling the request
The parameter that the closure receives is a Request
object that
represents the request made by the client.
The Request
object itself provides some getters, but most advanced functionnalities are
provided by other modules of this crate.
- In order to dispatch between various code depending on the URL, you can use the
router!
macro. - In order to serve static files, use the
match_assets
function. - ... TODO: write the rest
Modules
cgi | |
input |
Macros
assert_or_400 |
This macro assumes that the current function returns a |
find_route |
Evaluates each parameter until one of them evaluates to something else
than |
router |
Equivalent to a |
try_or_400 |
This macro assumes that the current function returns a |
Structs
LogEntry |
RAII guard that ensures that a log entry corresponding to a request will be written. |
Request |
Represents a request that your handler must answer to. |
Response |
Contains a prototype of a response.
The response is only sent when you call |
ResponseBody |
An opaque type that represents the body of a response. |
Session |
Represents an entry in the sessions manager. |
SessionsManager |
Manages all active user sessions in memory. |
Enums
RouteError |
An error that one of your routes can return. |
Functions
generate_session_id |
Generates a string suitable for a session ID. |
match_assets |
Searches inside |
start_server |
Starts a server and uses the given requests handler. |