Skip to content

Commit

Permalink
Merge pull request #77 from kana-rus/update_documents
Browse files Browse the repository at this point in the history
Update: `.header` docs, README, LICENSE year
  • Loading branch information
kanarus authored Feb 6, 2024
2 parents 309374e + 20e4621 commit 91385f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022 kanarus
Copyright (c) 2024 kanarus

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async fn main() {
)).howl("localhost:5000").await
}
async fn hello(name: &str) -> impl IntoResponse {
async fn hello(name: &str) -> String {
format!("Hello, {name}!")
}
```
Expand Down Expand Up @@ -209,35 +209,31 @@ async fn main() {
<br/>

### testing
```rust,no_run
```rust
use ohkami::prelude::*;
use ohkami::testing::*; // <--

fn hello_ohkami() -> Ohkami {
Ohkami::new((
"/hello".GET(|| async move {
OK("Hello, world!")
})
}),
))
}

#[tokio::main]
async fn main() {
hello_ohkami()
.howl(5050).await
}
#[cfg(test)]
#[tokio::test]
async fn test_my_ohkami() {
let hello_ohkami = hello_ohkami();
let ho = hello_ohkami();

let res = hello_ohkami.oneshot(TestRequest::GET("/")).await;
assert_eq!(res.status, http::Status::NotFound);
let req = TestRequest::GET("/");
let res = ho.oneshot(req).await;
assert_eq!(res.status(), Status::NotFound);

let res = hello_ohkami.oneshot(TestRequest::GET("/hello")).await;
assert_eq!(res.status, http::Status::OK);
assert_eq!(res.content.unwrap().text(), Some("Hello, world!"));
let req = TestRequest::GET("/hello");
let res = ho.oneshot(req).await;
assert_eq!(res.status(), Status::OK);
assert_eq!(res.text(), Some("Hello, world!"));
}
```

Expand Down
6 changes: 3 additions & 3 deletions ohkami/src/layer1_req_res/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ pub struct Request {pub(crate) _metadata: [u8; METADATA_SIZE],
method: Method,
/// Headers of this request
///
/// - `.headers.{HeaderName}()` to get the value
/// - `.headers.set().{HeaderName}(〜)` to mutate the value
/// - `.headers.set().{HeaderName}(append(〜))` to append the value
/// - `.{HeaderName}()` to get the value
/// - `.set().{HeaderName}(〜)` to mutate the value
/// - `.set().{HeaderName}(append(〜))` to append the value
pub headers: RequestHeaders,
pub(crate) path: Path,
queries: QueryParams,
Expand Down
6 changes: 3 additions & 3 deletions ohkami/src/layer1_req_res/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub struct Response {
pub status: Status,
/// Headers of this response
///
/// - `.headers.{HeaderName}()` to get the value
/// - `.headers.set().{HeaderName}(〜)` to set the value
/// - `.headers.set().{HeaderName}(append(〜))` to append the value
/// - `.{HeaderName}()` to get the value
/// - `.set().{HeaderName}(〜)` to set the value
/// - `.set().{HeaderName}(append(〜))` to append the value
pub headers: ResponseHeaders,
pub(crate) content: Option<Cow<'static, [u8]>>,
} const _: () = {
Expand Down

0 comments on commit 91385f7

Please sign in to comment.