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
0 answers

How to move cloned Arc into Rust Warp callback?

I'm trying to code a simple Warp server. type Cache = Arc>>; pub struct App { cache: Cache, // other fields } impl App { pub async fn new() -> App { /* App init */ } pub async fn run(self) { let…
KindFrog
  • 358
  • 4
  • 17
2
votes
1 answer

rust warp won't compile after switching filter orders

I have 3 filters, if I combine them in order a,c,b, the code compiles. But if I switch their orders like a,b,c, the code won't compile. The filter seems the same to me. Why? use reqwest::Method; use serde_json::Value; use warp::http::{HeaderMap,…
YNX
  • 511
  • 6
  • 17
2
votes
1 answer

Warp: single route works, multiple with .or() do not

Hoping someone can help me understand why running warp with a single route like this compiles fine: #[tokio::main] async fn main() -> Result<(), Box> { // GET /stats let stats = warp::get() …
t56k
  • 6,769
  • 9
  • 52
  • 115
2
votes
2 answers

returning a warp filter from function

I'm using warp to create a server in Rust. And let's say I have these two routes setup. let route_one = warp::get().and(warp::path("path1")).map(|| warp::reply()); let route_two = warp::get().and(warp::path("path2")).map(||…
Nick
  • 5,108
  • 2
  • 25
  • 58
2
votes
0 answers

How to redirect to URL with trailing slash in warp?

I am using warp to serve a directory of static files. Unfortunately the relative links used in those static files can only be resolved, when I add a trailing slash to my path. This is the code I use to serve the directory: let route =…
frankenapps
  • 5,800
  • 6
  • 28
  • 69
2
votes
1 answer

Warp and response types and trait objects?

I have a Warp rejection handler, I'm using it like this, .recover(handle_rejection) It's declared like this, pub async fn handle_rejection(err: Rejection) -> Result { If both sides of the if statement are the…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
2
votes
1 answer

How to serve CSS and JS files using Warp?

I want Warp to serve the current working directory. Here is the entire main.rs: #[tokio::main] async fn main() { let current_dir = std::env::current_dir().expect("failed to read current directory"); warp::serve(warp::fs::dir(current_dir)) …
user13150624
2
votes
0 answers

Type error when implementing TryFrom trait

I am trying to implement std::convert::TryFrom for warp::filters::ws::Message where OutputMessage is a simple struct that can be serialized with serde_json::to_string(): impl TryFrom for Message { type Error = (); …
lsgng
  • 465
  • 8
  • 22
2
votes
1 answer

Getting current path when handling rejections

I'd like to know how it would be possible to get HTTP path in Warp's rejection handler? I've got the following rejection method: pub(crate) async fn handle(err: Rejection) -> Result { let response = if err.is_not_found()…
Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107
2
votes
1 answer

Forwarding messages between BusReader and warp WebSocket sink leaves unflushed buffer?

I'm trying to create a websocket server (and HTTP, hence using warp) that forwards messages from one source (an MQTT subscription) to many clients over websockets. This mostly seems to work fine, aside from the clients not receiving the first…
2
votes
1 answer

How do I reuse paths in warp?

I'd like to have a hierarchical route structure with Rust warp like this: / /api /api/public /api/public/articles /api/admin /api/admin/articles I'd like to define my route scopes like in the following code, which is – of course – not…
LongHike
  • 4,016
  • 4
  • 37
  • 76
2
votes
1 answer

How to write incoming stream into a file in warp?

Goal: The server should be able to receive a stream of binary data and save it to a file. I'm getting this error: mismatched types expected `&[u8]`, found type parameter `B` How can I get a &[u8] from generic type B? use warp::Filter; use…
okorolko
  • 23
  • 3
2
votes
0 answers

Warp: Can't use ? in async route handler

I am trying to get an async handler working for a route using warp. I am doing some file operations with tokio. Here is a small example: use tokio::fs::File; use tokio::prelude::*; use warp::Filter; #[tokio::main] async fn main() { let route =…
Matthew Goulart
  • 2,873
  • 4
  • 28
  • 63
2
votes
2 answers

How can two headers of the same name be attached to a Warp `Reply`?

I'd like to write a function that returns impl Reply, i.e. a Warp handler. This function does some business logic and then should return two Set-Cookie headers; the contents of each cookie is different and dependent on the business logic. I had been…
maxcountryman
  • 1,562
  • 1
  • 24
  • 51
2
votes
1 answer

Hyper error: invalid certificate: UnknownIssuer

(I am adding this question after finding the solution as there was no matches for my error when I needed it.) After packaging a rust app as a docker container, I get the following error: Hyper error: invalid certificate: UnknownIssuer. I have used…
yngling
  • 1,376
  • 2
  • 22
  • 34