Skip to content

Commit 0c5757a

Browse files
karlivorywaghanza
andauthored
add khttp (#8590)
* add khttp * Update rust/khttp/config.yaml Co-authored-by: Marwan Rabbâa <[email protected]> * Update rust/khttp/Cargo.toml Co-authored-by: Marwan Rabbâa <[email protected]> --------- Co-authored-by: Marwan Rabbâa <[email protected]>
1 parent 01c1861 commit 0c5757a

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

rust/khttp/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "server"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
khttp = "0.1"
8+
9+
[profile.release]
10+
opt-level = 3
11+
codegen-units = 1
12+
panic = 'abort'
13+
lto = true
14+
debug = false
15+
incremental = false
16+
overflow-checks = false

rust/khttp/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
github: karlivory/khttp
3+
version: 0.1

rust/khttp/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use khttp::{Headers, Method::*, Server};
2+
use std::sync::LazyLock;
3+
4+
static BASE_HEADERS: LazyLock<Headers<'static>> = LazyLock::new(|| {
5+
let mut headers = Headers::new();
6+
headers.add(Headers::CONTENT_TYPE, b"text/plain");
7+
headers
8+
});
9+
10+
fn main() {
11+
let mut app = Server::builder("0.0.0.0:3000").unwrap();
12+
13+
// routes
14+
app.route(Get, "/", |_, res| res.ok0(&BASE_HEADERS));
15+
app.route(Post, "/user", |_, res| res.ok0(&BASE_HEADERS));
16+
app.route(Get, "/user/:id", |ctx, res| {
17+
let id = ctx.params.get("id").unwrap();
18+
res.ok(&BASE_HEADERS, id.as_bytes())
19+
});
20+
21+
// serve
22+
app.build().serve_epoll().unwrap();
23+
}

0 commit comments

Comments
 (0)