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
19
votes
8 answers

How to set up CORS or OPTIONS for Rocket.rs

I've got a backend running rocket.rs which my flutter web app sends a request to, but it can't get past the OPTIONS response. I have tried adding CORS (rocket_cors) to the backend and having a options response, but it still sends back: Error:…
Will
  • 1,059
  • 2
  • 10
  • 22
19
votes
2 answers

Return JSON with an HTTP status other than 200 in Rocket

I want my Rocket API to have a route like this: #[post("create/thing", format = "application/json", data="")] When the client sends { "name": "mything" }, everything should be alright and I know how to do that, but when it sends { "name":…
erictapen
  • 578
  • 3
  • 13
15
votes
1 answer

Rust Diesel: the trait bound `NaiveDateTime: Deserialize<'_>` is not satisfied

I am new to rust and diesel. And trying to create a small demo api using rocket framework. Getting error: the trait bound NaiveDateTime: Deserialize<'_> is not satisfied I googled and found some useful links like here :…
Shaksham Singh
  • 491
  • 1
  • 5
  • 19
15
votes
1 answer

How can I pass a variable initialized in main to a Rocket route handler?

I have a variable that gets initialized in main (line 9) and I want to access a reference to this variable inside of one of my route handlers. #[get("/")] fn index() -> String { return fetch_data::fetch(format!("posts"), &redis_conn).unwrap();…
Max
  • 965
  • 1
  • 10
  • 28
11
votes
1 answer

Installing latest rust nightly complains about missing rls component

Trying to compile: https://github.com/SergioBenitez/Rocket/tree/master/examples/hello Cargo.toml [dependencies] rocket = "0.4.10" Complains that I need rust nightly $ cargo build ... Error: Rocket (core) requires a more recent version of rustc. …
Chuck
  • 431
  • 4
  • 10
10
votes
1 answer

"Hello world" Rust webserver is slower than Node when measured from Chrome but not from curl

I created a repository with a Node.js based and a Rocket.rs based web server inside. Consider these steps: Start the Rocket.rs server via cargo run --release Start the Node.js server via node server.js Open http://localhost:8000/ (Rocket) and…
Attila Kun
  • 2,215
  • 2
  • 23
  • 33
9
votes
2 answers

How can I return JSON from a Rust (Rocket) HTTP endpoint?

What is the easiest way to return Json via Rocket in Rust? #[post("/route", data = "")] fn route(someVariable: String) -> String { // How can I return a json response here? {"a": "{someVariable}") } I tried: content::Json() but it seemed…
funerr
  • 7,212
  • 14
  • 81
  • 129
9
votes
3 answers

Can I use an async fn as a handler in Rocket?

I'm using Rocket framework and I want to make an async HTTP request in my handler, something like this #[get("/")] async fn handler() -> String { some_func().await; "OK".into() } And as a result, I get the next error the trait…
KonstantinB
  • 115
  • 1
  • 3
  • 8
8
votes
2 answers

Unable to use rocket::serde::json::Json despite both rocket and serde listed as dependencies

I followed the quickstart guide. Now I'm trying to return some super simple JSON and the documentation is wrong and there's no way to submit a ticket without getting on IRC. Error error[E0432]: unresolved import `rocket::serde::json` -->…
kalm42
  • 784
  • 9
  • 19
8
votes
2 answers

Rocket requires a minimum version of Rust nightly, but a higher stable version is already installed

I'm trying to run Rocket but I'm falling at the first hurdle. When trying to cargo run, I get the following error: error: failed to run custom build command for `pear_codegen v0.1.2` Error: Pear requires a nightly or dev version of Rust. Installed…
twigg
  • 3,753
  • 13
  • 54
  • 96
8
votes
1 answer

Serde's Serialize implementation not found for Rocket's UUID

I'm trying to create a custom struct using the UUID struct from Rocket as a field type. I want it to be serialized using Serde in order to convert it to JSON easily. When trying to do this, I get an error: error[E0277]: the trait bound…
Mestru
  • 387
  • 3
  • 11
7
votes
2 answers

Why is are my published ports not working?

I've created a docker image containing a rust application that responds to get requests on port 8000. The application itself is a basic example using the rocket library (https://rocket.rs/) it looks like this #![feature(proc_macro_hygiene,…
rvabdn
  • 947
  • 6
  • 20
7
votes
1 answer

Deserialization of JSON reponse keeps quotation marks in Strings

I am querying a Google API using reqwest: let request_url = format!( "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=*\ &inputtype=textquery\ &fields=formatted_address,name,place_id,types\ …
ludeed
  • 443
  • 6
  • 17
7
votes
1 answer

Compiler says that data cannot be shared between threads safely even though the data is wrapped within a Mutex

I'm using Rocket which has a State that it passes to the HTTP requests. This struct contains a Mutex which gives access to a SQLite database and is locked with a mutex to make read and writes safe. pub struct DatastoreInstance { …
Johan Bjäreholt
  • 731
  • 1
  • 11
  • 24
6
votes
3 answers

Build fails with Error: Pear requires a 'dev' or 'nightly' version of rustc even after a successful rustup override set nightly

Windows 10 rustup 1.23.1 (3df2264a9 2020-11-30) default rustc 1.50.0 (cb75ad5db 2021-02-10) project rustc 1.52.0-nightly (4a8b6f708 2021-03-11) rocket = "0.4.4" I'm trying to build a rust project with rocket but I always get this error when…
1
2 3
18 19