Skip to content

Commit

Permalink
refactor(example): use bytes in actix-kv
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Nov 15, 2024
1 parent ed91e86 commit 5ba61dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/actix-kv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = "4"
actix-web = "4.9.0"
log = { version = "0.4", features = ["release_max_level_info"] }
env_logger = "0.10.0"
fjall = { path = "../../" }
fjall = { path = "../../", features = ["bytes"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.99"

Expand Down
13 changes: 9 additions & 4 deletions examples/actix-kv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ async fn get_item(
let item = web::block(move || state.db.get(key)).await.unwrap()?;

match item {
Some(item) => Ok(HttpResponse::Ok()
.append_header(("x-took-ms", before.elapsed().as_millis().to_string()))
.content_type("application/json; utf-8")
.body(item.to_vec())),
Some(item) => {
// TODO: Not sure if this can be more elegant
let body = actix_web::body::BoxBody::new(actix_web::web::Bytes::from(item));

Ok(HttpResponse::Ok()
.append_header(("x-took-ms", before.elapsed().as_millis().to_string()))
.content_type("application/json; utf-8")
.body(body))
}
None => {
let body = json!(null);

Expand Down

0 comments on commit 5ba61dc

Please sign in to comment.