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

Lifetime issues with rocket fairings, tokio-scheduler and crons

I'm currently building an API engine on top of Rocket, and as modern apps do, I wanted to include an automated scheduler to run async tasks (aka crons) while the Rocket API is running. I decided to use Rocket fairings to enable the said scheduler…
2
votes
1 answer

Error on Post Method query_builder::QueryFragment / query_builder::QueryFragment

I am relatively new to rust and have really enjoyed playing around with it. However I am stuck on an error for my CRUD application using Diesel and Rocket. I have a main.rs, model.rs and schema.rs. I get an error with my POST method that uses the…
james
  • 23
  • 6
2
votes
1 answer

How can I access database pool outside of Rocket context?

I'm using the recommended rocket_db_pools crate to create a database pool and attach it to Rocket e.g. #[derive(Database)] #[database("birthdays")] struct DB(sqlx::SqlitePool); // in main rocket::build() .attach(DB::init()) I would like…
josephmr
  • 51
  • 3
2
votes
2 answers

How to redirect if a guard fail

I'm using a guard to authenticated a user. How can i easily redirect the user to the login page if a guard fail (redirect to /login in my example) ? #[rocket::async_trait] impl<'r> FromRequest<'r> for User { type Error = (); async fn…
Poxy
  • 51
  • 4
2
votes
0 answers

Custom openapi schema with rust, rocket and okapi

I am developing an API with Rust, using Rocket as main framework. To create the Swagger docs I use Okapi, which allows me to create the docs automatically. use rocket_okapi::swagger_ui::*; extern crate dotenv; use rocket_okapi::{openapi,…
Emille C.
  • 315
  • 2
  • 15
2
votes
0 answers

Rust Rocket - Obtaining database connection outside of controller

Currently when using Rust Rocket framework it is necessary to get your database connection via the controller. Basically the connection is given to your handler from a pre-configured pool. Now we have to pass this connection down into any struct…
TheCoolDrop
  • 796
  • 6
  • 18
2
votes
1 answer

SQLx to Mssql connection string

I'm learning rust and I've written my first very simple API using Rocket. Now I'd like to connect my server to an existing database I've got on MSFT Azure. I'm having a hard time finding examples on how this works for Mssql, the SQLx repository only…
picklepick
  • 1,370
  • 1
  • 11
  • 24
2
votes
0 answers

Is there a way to extend the route attribute macros to automate Rocket configuration?

Below is the "Hello world" example of Rocket, which only has one route handler (hello()): #[macro_use] extern crate rocket; #[get("/hello//")] fn hello(name: &str, age: u8) -> String { format!("Hello, {} year old named {}!", age,…
at54321
  • 8,726
  • 26
  • 46
2
votes
1 answer

Not using Async in Rocket 0.5+?

I read Rocket v0.5 now uses the Tokio runtime to support Async. I know Async can offer great scalability when we have lots of (like hundreds or thousands of) concurrent IO-bound requests. But many web/REST server apps simply don't fall into that…
at54321
  • 8,726
  • 26
  • 46
2
votes
1 answer

Why do I get "expected struct file1::A found struct file2::A" error when using a struct in multiple files?

I am trying to share a struct between two files, but I am getting an error. I have the following folder structure: src/ Models/ Login.rs Routes/ LoginRoute.rs Services/ LoginService.rs main.rs In Login.rs I…
Gonzalo
  • 45
  • 8
2
votes
1 answer

How to get this response JSON structure with Rocket (Rust)

I have a simple web service that I'm writing with Rocket, whenever data comes as a 200 response, it contains a vector of Strings. When an error comes, I want to have custom errors. And the structure I want to impose on those responses should be like…
Corel
  • 581
  • 3
  • 21
2
votes
2 answers

Rocket CORS how to return string with Request Guard?

I have a rocket (0.5.0-rc.1) route, that returns a content::Json and I would like to add CORS to that route using rocket_cors (from master). Specifically I want to use the RequestGuard, because I only want to enable CORS for certain…
frankenapps
  • 5,800
  • 6
  • 28
  • 69
2
votes
1 answer

How to workaround async incompatibilities when using mongodb-1.2.2 and rocket-0.5.0-rc.1?

I am working on building a rocket REST API using a mongodb database. I have been able to successfully create a connection and start up the server without errors: # Cargo.toml [dependencies] rocket = "0.5.0-rc.1" dotenv = "0.15.0" mongodb =…
Lukas
  • 149
  • 3
  • 9
2
votes
1 answer

Rocket - Use state within my guards fails as traits are not implemented

I want to use state within my guards. I want to have routes that required authentication with an api key which I want to define in my Rocket.toml. But running this code I get the following error: the trait From<(Status, ())> is not implemented for…
Greeneco
  • 691
  • 2
  • 8
  • 23
2
votes
1 answer

Webserver only launches from http://localhost:8000

I'm running this hello world example: https://rocket.rs/v0.4/guide/quickstart/#running-examples $ cargo run Finished dev [unoptimized + debuginfo] target(s) in 1.32s Running `C:\Users\m3\repos\Rocket\target\debug\hello_world.exe` Configured…
Megidd
  • 7,089
  • 6
  • 65
  • 142