Questions tagged [rust-rocket]

A Rust web framework that uses unstable nightly features to provide a highly ergonomic and type-safe experience.

Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety. All with minimal code.

Useful links

281 questions
2
votes
1 answer

Accessing the Rocket 0.4 database connection pool in a request guard

I am creating a webapp with authentication using Rocket. To do this, I created a User struct that implements FromRequest. It takes the authorization header, which contains a JSON Web Token. I deserialize this token to obtain the payload, and then I…
Luuk Wester
  • 189
  • 2
  • 10
2
votes
3 answers

How to use a date in the url with Rocket.rs?

How would you alter the example from Rocket's website to take a date rather than an age/u8? The example from the website: #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; #[get("/hello//")] fn hello(name:…
pandark
  • 313
  • 1
  • 10
2
votes
0 answers

Rocket.rs route by subdomain

Is there a way to handle requests from different subdomains differently? For example, I have www.example.com which I'd like to return www.html and aaa.example.com which I'd like to return aaa.html. I know how to get the hostname, and I could always…
vcapra1
  • 1,988
  • 3
  • 26
  • 45
2
votes
2 answers

Invalid or unexpected token in WebAssembly

I am trying to run a WebAssembly program (written in Rust, the example-program from https://rustwasm.github.io/book/game-of-life/hello-world.html) with Rocket. The WebAssembly is compiled with wasm-pack and using the wasm_bindgen. The wasm binary is…
Ben Müker
  • 31
  • 5
2
votes
1 answer

How do I fix mismatching dependencies in my Cargo file to work around native library collisions?

I'm setting up a Rust server with Rocket and I'm trying to use it with a JWT library. They use different versions of the *ring* crate and I get an error during cargo build: error: multiple packages link to native library `ring-asm`, but a native…
drpytho
  • 125
  • 2
  • 10
2
votes
2 answers

Unable to build Rocket.rs: The given version requirement is invalid

I am following the Rocket getting started guide to learn the Rocket web framework for Rust. When I execute cargo run --verbose I get the following error: PS C:\Users\kin\Desktop\hello-rocket> cargo run --verbose Updating registry…
Casper
  • 4,435
  • 10
  • 41
  • 72
2
votes
2 answers

Can I render a Template in Rocket with my own serialized struct?

I'm using Rocket and I'm trying to create a Layout struct. I've implemented serde::Serialize, because the documentation says the static method Template::render's second argument accepts a struct that implements Serialize: struct Layout { data:…
1
vote
2 answers

What does returning `_` mean in Rust?

I'm a newbie in rust lang. What does returning -> _ mean for the rocket function? #[launch] fn rocket() -> _ { rocket::build() .attach(json::stage()) .attach(msgpack::stage()) .attach(uuid::stage()) }
1
vote
0 answers

How to show headers in swagger UI using `rocket_okaapi`

I currently have a Login struct (email, password) and an associated request guard that checks if the needed email and password headers are in the request. If so the struct is built and passed to the route if not a 401, Bad Request is returned. MY…
Dilec Padovani
  • 149
  • 1
  • 8
1
vote
0 answers

Implement responder with dynamic status code

I'm implementing a generic error responder to handle errors in the rocket rust web framework. Following the docs here: https://rocket.rs/v0.5-rc/guide/responses/#custom-responders This responder works for me: #[derive(Responder)] #[response(status=…
Willem D'Haeseleer
  • 19,661
  • 9
  • 66
  • 99
1
vote
1 answer

Serve mp3 files from Rust Rocket [Chrome compatibel]

I have the problem that my server does not respond with a 206 Partial Content as described here. Changing the audio elements attribute currentTime only works in Firefox but not in Chrome. I implemented an own static file hosting with this code: use…
Samuel
  • 547
  • 1
  • 3
  • 14
1
vote
1 answer

error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as`

I want to send query to database, but I faced this error: this error originates in the macro $crate::sqlx_macros::expand_query which comes from the expansion of the macro sqlx::query_as (in Nightly builds, run with -Z macro-backtrace for more…
Mr Coder
  • 761
  • 2
  • 13
  • 34
1
vote
1 answer

How to access database connection from a Rocket's fairing?

I'm trying to use database connection from a Rocket's on_ignite fairing: use sqlx::{ self, FromRow }; use rocket::fairing::{self, Fairing, Info, Kind}; use rocket::{Build, Rocket}; use crate::database::PostgresDb; #[derive(FromRow)] struct…
1
vote
0 answers

Cookie has been rejected because it is in a cross-site context (Nginx, Nextjs, Rocket)

My development workflow is as follow: I access the frontend via https://client.my-project:3001. Nginx proxies it to nextjs's local server at localhost:3000. In a react component there's a function handlesubmit in which fetch sends a post request to…
mvannsec
  • 41
  • 2
1
vote
0 answers

How to connect to a redis cluster using rocket_db_pools

use rocket_db_pools::{deadpool_redis, Database}; #[derive(Database)] #[database("redis_tests")] pub struct TestRedisPool(deadpool_redis::Pool); As above, we are connecting to redis using deadpool_redis in rocket_db_pools. The address of the…
white-dog
  • 11
  • 1