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
1
vote
1 answer

what is the difference about rocket launch and main entrypoint

I am using rust rocket rocket = { version = "=0.5.0-rc.2", features = ["json"] } as my web server, today I found there is two way to start the rocket, one of the start like this: #[rocket::main] async fn main() { // the rocket start…
Dolphin
  • 29,069
  • 61
  • 260
  • 539
1
vote
2 answers

How to test two parallel transactions in Rust SQLx?

I'm experimenting with Rocket, Rust and SQLx and I'd like to test what happens when two parallel transactions try to insert a duplicated record on my table. My insert fn contains nothing special and it works fine: async fn insert_credentials<'ex,…
André
  • 12,497
  • 6
  • 42
  • 44
1
vote
1 answer

How to catch all routes in rocket?

I have looked up everywhere but I only found this github issue, but it's from 5 years ago, and rocket has changed a lot. Is there a way to catch all methods (get, post, head, options, whatever .. .) and all routes (/abc, /abc/xyz, /xyz, /whatever)…
user18511546
1
vote
0 answers

macro_use equivalent for crate-wide macro use - re-exporting rust-rocket

I am trying to have the rocket crate dependency into a 'common' crate and to re export it for use in my 'test' crate. This is what I tried: common: #lib.rs #[macro_use] pub extern crate rocket; test: #main.rs #[macro_use] extern crate…
kurito
  • 43
  • 2
  • 4
1
vote
1 answer

Lifetimes do not match method in trait

I have an asynchronous responder impl, but something is wrong with the lifetime of the objects. The code: #[rocket::async_trait] impl<'r> Responder<'r, 'static> for LoginUser { async fn respond_to(self, _: &'r Request) ->…
1
vote
1 answer

Unity's UnityWebRequest GET fails for http://localhost:8000 when HttpClient, browser, and postman all succeed? Server is in Rust: Rocket

To keep things short trying to get a Unity client to work. It is making a simple Get request to: "http://localhost:8000/api/board". This request works fine: in my browser postman .net's HttpClient inside Unity editor mode if I build and run a WebGL…
1
vote
0 answers

Is it possible to attach a Rocket request guard onto all routes?

I'm trying to block all access using Basic HTTP Authentication, but wish to avoid accidentally forgetting any routes. I thought that perhaps it could be implemented through a Fairing, but I cannot see how that would work given that "Fairings cannot…
TimY
  • 5,256
  • 5
  • 44
  • 57
1
vote
1 answer

Global authentication/authorization in Rocket based on a header

I know I can use a Request guard. However, if I have a REST API with hundreds of handlers, not only it would be annoying to have to add an extra function param to all of them, but it kinda scares me that it could be easy to miss adding such a param…
at54321
  • 8,726
  • 26
  • 46
1
vote
1 answer

How to add custom headers to content::JSON in Rocket?

Say I have this route handler in rocket (v. 0.5.0-rc.1): #[get("/route")] pub async fn my_route() -> content::Json { let json = rocket::serde::json::serde_json::to_string(&my_data).unwrap(); content::Json(json) } how could I…
frankenapps
  • 5,800
  • 6
  • 28
  • 69
1
vote
1 answer

'rocket-worker-thread' panicked at 'Cannot drop a runtime in a context where blocking is not allowed'

I'm trying to call a downstream API and return the results as a Json object. I'm using reqwest which uses tokio: Cargo.toml [dependencies] rocket = { version = "0.5.0-rc.1", features = ["secrets", "tls", "json"] } reqwest = { version = "0.11",…
Nightwolf
  • 4,495
  • 2
  • 21
  • 29
1
vote
0 answers

How to get State in FromRequest implementation with Rocket?

I initialized a Mutex> instance and passed it to manage method on Rocket instance in order to access the database on my controllers. What I usually do is: // this is purely for example #[get("/foo/bar")] pub async fn controller<'a>( …
Eray Erdin
  • 2,633
  • 1
  • 32
  • 66
1
vote
1 answer

Read Response as JSON from request made to an IPFS in rust

I have create a server using rocket to access the peer information of an ipfs URL The program as follows #[macro_use] extern crate rocket; use rocket::local::asynchronous::Client; use rocket::http::hyper::{Request, Response}; use…
not 0x12
  • 19,360
  • 22
  • 67
  • 133
1
vote
1 answer

Some config options ignored when building a Rust program that uses Rocket-rs in a container

I have a very strange issue with my Rust program that uses the rocket-rs library. The issue I am facing is that when I try and build my program in a Docker container using a Dockerfile I created, some parts of the config I set out in the rocket.toml…
nlanson
  • 357
  • 1
  • 3
  • 14
1
vote
1 answer

How to get the database Connection in rocket.rs Fairing

How can I access the database in a Fairing in Rust Rocket (0.5-rc1) with rocket_sync_db_pools? In routes, I can just request it as a parameter like so: #[get("/")] pub async fn index(db: Database) -> Json { ... } But when registering an…
1
vote
0 answers

How to add compressed scripts in Rust-Rocket?

I'm new in Rust and Rocket. I mount my static files in Rocket as follows: .mount("/", StaticFiles::new("static", options)) It works good for images or styles but it's not quite what I expect from adding of scripts. I want to use compressed script…