aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 2433c76e84b9926df7b4396e043a466ce5f6790d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Windmark

[![crates.io](https://img.shields.io/crates/v/windmark.svg)](https://crates.io/crates/windmark)
[![docs.rs](https://docs.rs/windmark/badge.svg)](https://docs.rs/windmark)
[![github.com](https://github.com/gemrest/windmark/actions/workflows/check.yaml/badge.svg?branch=main)](https://github.com/gemrest/windmark/actions/workflows/check.yaml)

Windmark is an elegant and highly performant, async Gemini server framework for
the modern age!

Now supporting both [Tokio](https://tokio.rs/) and [`async-std`](https://async.rs/)!

## Usage

A macro-based "`struct`-router" is currently being developed for Windmark. A
subset of Windmark's features are currently available for use through it. Check
out [Rossweisse](./rossweisse/) for more information!

### Features

| Feature            | Description                                                                                             |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| `default`          | Base Windmark framework using [Tokio](https://tokio.rs/)                                                |
| `logger`           | Enables the default [`pretty_env_logger`](https://github.com/seanmonstar/pretty-env-logger) integration |
| `auto-deduce-mime` | Exposes `Response`s and macros that automatically fill MIMEs for non-Gemini responses                   |
| `response-macros`  | Simple macros for all `Response`s                                                                       |
| `tokio`            | Marks [Tokio](https://tokio.rs/) as the asynchronous runtime                                            |
| `async-std`        | Marks [`async-std`](https://async.rs/) as the asynchronous runtime                                      |
| `prelude`          | Exposes the `prelude` module containing the most used Windmark features                                 |

### Add Windmark and Tokio as Dependencies

```toml
# Cargo.toml

[dependencies]
windmark = "0.3.9"
tokio = { version = "1.26.0", features = ["full"] }

# If you would like to use the built-in logger (recommended)
# windmark = { version = "0.3.9", features = ["logger"] }

# If you would like to use the built-in MIME dedection when `Success`-ing a file
# (recommended)
# windmark = { version = "0.3.9", features = ["auto-deduce-mime"] }

# If you would like to use macro-based responses (as seen below)
# windmark = { version = "0.3.9", features = ["response-macros"] }
```

### Implementing a Windmark Server

```rust
// src/main.rs

// ...

#[windmark::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  windmark::router::Router::new()
    .set_private_key_file("windmark_private.pem")
    .set_certificate_file("windmark_public.pem")
    .mount("/", windmark::success!("Hello, World!"))
    .set_error_handler(|_|
      windmark::response::Response::permanent_failure("This route does not exist!")
    )
    .run()
    .await
}
```

### Implementing a Windmark Server Using Rossweisse

```rust
// src/main.rs

// ...

#[rossweisse::router]
struct Router;

#[rossweisse::router]
impl Router {
  #[route(index)]
  pub fn index(
    _context: windmark::context::RouteContext,
  ) -> Response {
    Response::success("Hello, World!")
  }
}

// ...
```

## Examples

Examples can be found within the
[`examples/`](https://github.com/gemrest/windmark/tree/main/examples) directory
along with a rundown of each of their purposes and useful facts.

Run an example by cloning this repository and running `cargo run --example example_name`.

## Modules

Modules are composable extensions which can be procedurally mounted onto Windmark
routers.

### Examples

- [Simple Stateless Module](https://github.com/gemrest/windmark/blob/main/examples/stateless_module.rs)
  \- Mounts the `/smiley` route, returning an 😀 emoji
- [Simple Stateful Module](https://github.com/gemrest/windmark/blob/main/examples/stateful_module.rs)
  \- Adds a click tracker (route hit tracker) that additionally notifies before and after route visits
- [Windmark Comments](https://github.com/gemrest/windmark-comments) - A fully featured comment engine
  for your capsule

## License

This project is licensed with the
[GNU General Public License v3.0](https://github.com/gemrest/windmark/blob/main/LICENSE).