π¦ Fluffer
Fluffer is a fun and experimental gemini server framework.
π Overview
Routes are generic functions that return anything implementing the [GemBytes]
trait.
There are some helpful implementations out of the box. Please consult
[GemBytes] and [Fluff] while you experiment. Also check out the examples.
use ;
async
π GemBytes
The [GemBytes] trait has one method for returning a gemini byte response:
<STATUS><SPACE><META>\r\n<CONTENT>
Remember you must include the <SPACE> characterβeven if <META> is blank.
To implement [GemBytes] on a type is to decide the response appropriate for
it.
For example: you may represent a mime-ambiguous type as formatted gemtext.
use ;
π Identity
Gemini uses certificates to identify clients. The [Client] struct implements
common functionality.
π Input, queries, and parameters
Input
Calling [Client::input] returns the request's query line percent-decoded.
default
.route
.run
.await
.unwrap
Queries
For routes where you aren't also accounting for a user's input, queries are suitable for tracking UI state across requests.
For example, you can add warning or error messages to a
gemtext document by redirecting to a path with special query
names. (E.g. /home?err=bad%20thingg%20happened),
The Fluff variant [Fluff::RedirectQueries] helps by redirecting to a route
with a vector of key-value queries.
Use [Client::query] to inspect query values.
Parameters
Parameters are derived from patterns you define in a route's path.
Define a parameter in your route string, and access it by calling
[Client::parameter].
default
.route
.run
.await
.unwrap
If you're unfamiliar with [matchit], here are a few examples:
"/owo/:A/:B"definesAandB. (/owo/this_is_A/this_is_B)"/page=:N/filter=:FdefinesNandF. (/page=20/filter=date)
Keep in mind: some clients cache pages based on their url. You may want to avoid using parameters in routes that update frequently.
π State
Fluffer allows you to choose one data object to attach as a generic to
[Client].
use App;
use ;
// Alias for Client<State>
type Client = Client;
async
async
π Titan
Titan is a sister protocol for uploading files.
You can enable titan on a route by calling [App::titan] instead of
[App::route].
On a titan-enabled route, the titan property in [Client] may yield a resource.
use ;
async
async
β¨ Features
| Name | Description | Default |
|---|---|---|
interactive |
Enable prompt for generating key/cert at runtime. | Yes |
anyhow |
Enable [GemBytes] for anyhow (not recommended outside of debugging) |
No |
reqwest |
Enable [GemBytes] for reqwest::Result and reqwest::Response |
No |