Questions tagged [rust-warp]

rust warp is a super-easy, composable, web server framework for warp speeds. The main concept in warp is the Filter.

warp is a super-easy, composable, web server framework for warp speeds. Thanks to its Filter system, warp provides these out of the box:

  • Path routing and parameter extraction
  • Header requirements and extraction
  • Query string deserialization
  • JSON and Form bodies
  • Static Files and Directories
  • Websockets
  • Access logging

The main concept in warp is the Filter, which allows composition to describe various endpoints in your web service. Besides this powerful trait, warp comes with several built in filters, which can be combined for your specific needs.

https://docs.rs/warp/

92 questions
2
votes
2 answers

Trouble configuring Rust's Warp Filters

I'm trying to setup a simple GET filter, but I'm having trouble getting it to compile. This is the function I'm trying to map to the request: pub async fn get_users(reference_counter: Arc>) -> Result { …
AxiomaticNexus
  • 6,190
  • 3
  • 41
  • 61
2
votes
1 answer

Is there a simpler way to create a custom Filter method to invoke a Warp handler?

Instead of writing something like: let hello = get() .and(path!(String)) .and_then(|string| handlers::hello(string).map_err(warp::reject::custom)) .boxed() I'd like to be able to write: let hello = get() .and(path!(String)) …
2
votes
1 answer

Future trait not implemented when using Warp’s and_then

I'm trying add HTTPS enforcement to my Warp-based web app on GKE. The GKE platform is mostly irrelevant; the cromulent detail is that the load balancer terminates SSL/TLS connections, so the “real” scheme is provided in the X-Forwarded-Proto header.…
MTCoster
  • 5,868
  • 3
  • 28
  • 49
2
votes
1 answer

Serve Static Files using warp in rust

I am using warp library to make a web app in rust. I am trying to serve the static files. I have read its documentation from Doc. Here is my code snippet use serde::Deserialize; use serde::Serialize; use warp::path; use…
kumarmo2
  • 1,381
  • 1
  • 20
  • 35
2
votes
1 answer

How can I create a variable path in Warp?

I'm trying to have a variable path in Warp. I have tried this: use uuid::Uuid; use warp::{self, Filter}; fn main() { let uuid = Uuid::new_v4(); println!("{}", uuid); let hello = warp::path(&uuid.to_string()).map(|| "hello world"); …
carloabelli
  • 4,289
  • 3
  • 43
  • 70
1
vote
2 answers

How to get path from URL in warp?

I am using warp to build a Proxy. The proxy doesn't care about parameters or path, it just delegate requests from clients. So the client may query like: https://proxy.com/p1?a=1&b=2 or https://proxy.com/p2?c=1 or many other different paths I want to…
YNX
  • 511
  • 6
  • 17
1
vote
1 answer

Warp duplicates responses on unrelated paths

I'm trying to make a web server with a prometheus endpoint to put out metrics on my other pages. I'm running into an issue with collecting those metrics. It stems from warp seemingly executing each route on every request, with every route that that…
myaple
  • 21
  • 2
1
vote
1 answer

Creating a warp path filter for get request

I am a Rust beginner and I needed some help with creating path Filters. The stripped down code looks like this: pub fn requests_filter() -> impl Filter + Clone { let authenticate =…
vidhatha
  • 13
  • 3
1
vote
1 answer

Rust warp+sqlx service : idiomatic way of passing DBPool from main to handlers

A Rust newbie here, attempting to write a webservice by combining https://github.com/seanmonstar/warp/blob/master/examples/todos.rs and https://github.com/launchbadge/sqlx/blob/master/examples/postgres/todos/src/main.rs The following code is in…
so-random-dude
  • 15,277
  • 10
  • 68
  • 113
1
vote
2 answers

How do I clone a variable before moving it into warp's .then() filter?

I have the following code snippet: async fn server(config: crate::Config) { println!("Building server"); let key = hmac::Key::new(hmac::HMAC_SHA256, config.docusign.hmac_key.as_bytes()); let webhook = warp::path("webhook") …
The Mungler
  • 136
  • 1
  • 12
1
vote
1 answer

Loop through arc and pop values in different thread

I'm trying to implement a shared state (arc) for a Warp route. Given this main function: #[tokio::main] async fn main() { let ack_vec: Vec = Vec::new(); let arc = Arc::new(Mutex::new(ack_vec)); // GET /call/:id …
t56k
  • 6,769
  • 9
  • 52
  • 115
1
vote
1 answer

redirect or show HTML with warp in rust?

I'm doing some code training with warp and rust and I want to do something like the following: let route = warp::path("my") .and(warp::path::param()) .map(|filename: String| { match fs::read_to_string(filename) { …
Esteban Zapata
  • 311
  • 2
  • 7
1
vote
1 answer

Warp error: error[E0277]: the trait bound `impl warp::Future: warp::filter::FilterBase` is not satisfied

Warp is returning the error, error[E0277]: the trait bound `impl warp::Future: warp::filter::FilterBase` is not satisfied --> src/http.rs:31:26 | 31 | let routes = index().or(users()); | ^^^^^^^ the trait…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
1
vote
1 answer

Warp asks for absurdly long and complex explicit type annotations, is there another way?

I'm getting the following error, error[E0283]: type annotations needed for `warp::filter::and_then::AndThen, impl…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
1
vote
1 answer

How do I integrate warp with async libraries?

Warp has a paradigm like this, let hi = warp::path("hello") .and(warp::path::param()) .and(warp::header("user-agent")) .map(|param: String, agent: String| { format!("Hello {}, whose agent is {}", param, agent) }); Those…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468