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

Unit tests with Rocket.rs

Im trying to write some unit tests for the 3 routes of my Rocket app. So far the get index function works fine but the two post requests arent working Im getting confused because i keep getting a 404 request and i don't really know why tests.rs: use…
Oscar S
  • 11
  • 2
1
vote
1 answer

Rust async streams blocking workers

I'm trying to implement an rocket.rs route that allows me to notify a client from the server. Here is the minimal example I'm testing with: use rocket::response::stream::Event; use std::time::Duration; use…
BenStr
  • 11
  • 3
1
vote
1 answer

Implementing trait generics in map struct fields

So for a rocket project, I decided to setup a security system that will handle grants based of Security voters (a naive version of Symfony ones). I decided to implement as Security struct to contain a HashMap with HashMap where the string…
1
vote
1 answer

rocket.rs 0.5-rc2 compilation in alpine linux

I recently upgraded my application to rocket v0.5-rc2 and I'm encountering new errors where the linker fails to find crti.o ARG BINARY_NAME=rocketdieselstack FROM rust:alpine3.16 as builder RUN rustup update nightly && rustup default…
crlsktr
  • 105
  • 1
  • 15
1
vote
2 answers

Rocket Deserialize 'de lifetime

I am new to Rust and trying to learn. I am using Rocket to create an API endpoint that passes in some key/value pairs. I've defined my structs like this: #[derive(Deserialize)] #[serde(crate = "rocket::serde")] #[derive(Debug)] struct…
CleverPatrick
  • 9,261
  • 5
  • 63
  • 86
1
vote
1 answer

Rust + rocket: Return file using `NamedFile` gives wrong file extension

Using xlsxwriter, I have created an .xlsx file ( fn create_workbook()) that I want to send to the client using rocket. Downloading works, but the extension is wrong. Ideally, the file should be deleted after the client has downloaded it. Creating…
black
  • 1,151
  • 3
  • 18
  • 46
1
vote
1 answer

Rust/Rocket/Diesel - How can I query a MySqlDatabase using rocket_sync_db_pools

When trying to call load on my prices schema created by diesel in a Rocket app, I get the error the trait LoadConnection is not implemented for &mut rocket_sync_db_pools::diesel::MysqlConnection I've looked at a few tutorials, and have followed the…
1
vote
2 answers

How to handle a failure to get a connection from the database pool?

I'm building an API using Rocket and Diesel, and I'm managing the DbPool using Rocket's State. A search request handler might look like this, then: #[get("/search?")] pub fn general_privileged( db_pool: &State, _key:…
tcmoore
  • 1,129
  • 1
  • 12
  • 29
1
vote
1 answer

What is the difference between rocket::ignite() and rocket::build()?

I'm learning rocket framework and I came a cross with method after you launch the application. #[launch] fn rocket() -> _ { rocket::build().mount("/", routes![index]) } or without attribute "launch" fn main() { rocket::ignite() …
Shinomoto Asakura
  • 1,473
  • 7
  • 25
  • 45
1
vote
0 answers

How can I return JSON struct with an HTTP status in Rocket 0.5.0-rc.2?

I'm searching a clean and good way to return json responses with the right HTTP status using Rocket 0.5.0-rc.2. I want something versatile that I can use to return error messages (in case of error) but also JSON results (in case of 200) from…
Stefano Cappa
  • 575
  • 3
  • 17
1
vote
1 answer

Rust Rocket REST API

I can not compile main.rs file. And in probabilityofunitinjectorfail I want to add random generated number 0-100. error: cannot find function 'iginite' in create 'rocket'. Here is main.rs: #![feature(decl_macro)] #[macro_use] extern crate…
Tytus Bomba
  • 23
  • 1
  • 5
1
vote
1 answer

How to get rocket::serde::json::Json as a JSON string?

I am trying to write a struct from a request payload to kafka, to do it I need to obtain the JSON string representing the struct. Currently, I am loading the object from the request using a struct that implements the Deserialize and Serialize traits…
rafaelleru
  • 367
  • 1
  • 2
  • 19
1
vote
1 answer

How to fix mismatched Results using #[launch] when upgrading from Rocket 0.5.0-rc.1 to rc.2?

I'm trying to get a simple API up and running using rocket similar to this repo: //! main.rs use ptb_api; // my crate #[rocket::main] async fn main() -> Result<(), rocket::Error> { ptb_api::rocket().launch().await } //! lib.rs use…
stegnerd
  • 1,119
  • 1
  • 17
  • 25
1
vote
1 answer

How can you access a rocket(rust) state at the end of the servers life?

I want to be able to do something with my state once the server starts shutting down example: struct MyConfig { user_val: String } #[get("/hello")] fn hello(config: &State) -> Result { //do stuff …
1
vote
1 answer

Error: Rocket failed to launch due to failing fairings:

I am just learning Rust's Rocket however when I compile the code, I get errors mentioned below. I am just trying to pass values to my templates variable from my rust file. I have a src/main.rs file with following code: #[macro_use] extern crate…
IcanCode
  • 509
  • 3
  • 16