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
0
votes
1 answer

Rust - Suddenly Can't find split method on WebSocket?

I'm a rust newbie and I'm having a lot of trouble getting some simple ws examples to run. I have a new project with this in the Cargo.toml file: [package] name = "ouranos4" version = "0.1.0" authors = ["jasongoodwin…
JasonG
  • 5,794
  • 4
  • 39
  • 67
0
votes
1 answer

Return owned string in warp::reply::with_status

I have a warp server running, and for every request I need to compute a string and then return that string with a particular status code. use warp::{http::StatusCode, reply, Filter}; let creator = warp::post() .and(warp::path("mypath")) …
Lumin
  • 373
  • 6
  • 21
0
votes
0 answers

Mysterious drop of oneshot reciever in rust webserver

I'm making my webserver in rust using warp and tokio. Here's what I'm doing : I'm creating three tokio runtimes, and executing 3 async functions on them, all of which communicate with each other using channels. I'm doing this because I'm making a…
Rohan Gautam
  • 146
  • 1
  • 9
0
votes
2 answers

Why does warp return HTTP 405 Method Not Allowed for incorrectly typed parameters?

Consider the following route specification in warp: let read_book_route = warp::path!("book" / Address) .and(warp::get()) .and(warp::any().map(move || read_book_state.clone())) .and_then(handler::read_book_handler); If a…
sporejack
  • 71
  • 1
  • 6
0
votes
1 answer

Mismatch between lifetime of closure body and value passed into it

I have the following situation: let rpc_endpoint: String = matches.value_of("rpc_endpoint").unwrap().to_owned(); /* later on... */ let create_order_route = warp::path!("book" / String) .and(warp::post()) …
sporejack
  • 71
  • 1
  • 6
0
votes
1 answer

Reusing a moved variable for warp filters

I want to use Rust and Juniper to create a GraphQL server. This server has to access the database. I've been trying to follow this example code from Juniper but it uses an empty Context to give over to the Schema; I need to send a pool for database…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
0
votes
2 answers

Can't get async closure to work with Warp::Filter

I am trying to get an async closure working in the and_then filter from Warp. This is the smallest example I could come up with where I am reasonably sure I didn't leave any important details out: use std::{convert::Infallible, sync::Arc, thread,…
Matthew Goulart
  • 2,873
  • 4
  • 28
  • 63
0
votes
2 answers

Warp filter moving variable out of its environment

I am trying to implement a filter that sits in all my routes and extracts a header and matches a possible token to what is stored on my system. I want to implement something like the warp rejection example but I get the error expected a closure…
Glenn Pierce
  • 720
  • 1
  • 6
  • 18
0
votes
1 answer

What to do if an external crate requires static lifetime explicitly?

I'm using seanmonstar/warp to build my rest service and faced the problem related to lifetimes. Here is how my application starting code looks like: struct MyModelStruct { //... } struct Database { //... } impl Database { fn connect(/*…
Some Name
  • 8,555
  • 5
  • 27
  • 77
0
votes
2 answers

Trait std::convert::From not implemented for hyper::body::Body

lazy_static::lazy_static! { static ref file_data: String = fs::read_to_string("static/login.html").expect("unable to read from static/login.html"); } #[tokio::main] async fn main() { // code omitted let login =…
너를 속였다
  • 899
  • 11
  • 26
0
votes
1 answer

Type annotations needed for String when using AsRef

I'm using Warp like this: #[derive(Default)] struct State { topics: HashMap, } struct Topic { name: String, description: String, items: Vec, } fn with_state(state: Arc>) -> impl Filter
Timmmm
  • 88,195
  • 71
  • 364
  • 509
0
votes
1 answer

How do we redirect to an external URL in warp?

I want to redirect to an external URL like https://www.google.com, but warp::redirect only only takes a URI and not a URL.
-1
votes
1 answer

Accessing main-scoped awaitable hashmap from within a task without using channels

I am checking out WebSocket frameworks for Rust and ended up watching a tutorial video on Warp (https://www.youtube.com/watch?v=fuiFycJpCBw), recreated that project and then compared it with Warp's own example implementation of a chat server. I…
Daniel F
  • 13,684
  • 11
  • 87
  • 116
-1
votes
1 answer

How do I spawn a thread inside of Warp to handle async behavior?

I am using the Warp crate for a web service, but I am having problems getting it running from my non-async main. I have tried several ways and the closest I have gotten is this: Cargo.toml [dependencies] warp = "0.3" futures = "0.3" Code: use…
Tim Ross
  • 19
  • 3
-2
votes
1 answer

Warp with Mongo DB Global Resource Injection

I have set up a database connection but I want to share it with my warp API handlers. my Cargo.toml [package] name = "mongo-warp" version = "0.1.0" edition = "2021" # See more keys and their definitions at…
Bill
  • 4,614
  • 13
  • 77
  • 132