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
3
votes
3 answers

How can Rust Rocket deduce return types wrapped in Results/Options?

This is probably not a high-quality question as I am new to Rust. I'm working with Rocket. Rocket handlers can return "A value of any type that implements the Responder trait". However, I notice that I can wrap something that implements Responder…
sg_man
  • 763
  • 1
  • 6
  • 14
3
votes
1 answer

How do I parse a JSON body in Rocket when the content type is not "application/json"?

I'm trying to parse this JSON CSP Record being submitted via POST directly by the browser into a nested…
Patrick
  • 1,562
  • 1
  • 16
  • 33
3
votes
1 answer

Cannot find macro `log` in this scope when using log with Rocket

I am getting a compiler error trying to use the log crate in a package in a workspace. The other crates in the workspace are using logging without problem. Cargo.toml: [dependencies] log = "^0" rocket = "^0" [dependencies.uuid] version =…
Jeff Ruby
  • 51
  • 1
  • 4
3
votes
1 answer

Error when sending POST request from React app to Rocket backend returns failure

I'm writing a simple web with Rocket as backend and React as frontend. The code snippet looks like this for login page #[post("/login", data = "")] pub fn login( conn: DbConn, mut cookies: Cookies<'_>, data: Form, ) ->…
3
votes
1 answer

How to write column names with whitespace in diesel model.rs?

I am trying to use Diesel to manage my database to use with Rocket and i got stuck at writing the models.rs for my table: CREATE TABLE `problemSet` ( `id` varchar(10) NOT NULL, `contestId` int DEFAULT NULL, `difficulty` varchar(10) DEFAULT…
3
votes
2 answers

How to run Diesel migration with Rocket in production?

I need to run Diesel database migrations in production for a Rocket-based app. Generally there are to ways to perform migrations for the database: At application startup. Separately from application startup. I prefer the second option that would…
SS_Rebelious
  • 1,274
  • 2
  • 19
  • 35
3
votes
1 answer

How can I set the HTTP status code of a (Rust) Rocket API endpoint's Template response?

I have the following login POST endpoint handler in my Rocket API: #[post("/login", data = "")] pub fn login_validate(login_form: Form) -> Result { let user = get_user(&login_form.username).unwrap(); …
Daniel Gray
  • 1,697
  • 1
  • 21
  • 41
3
votes
0 answers

Supporting range requests using Rocket

I know Rocket has support for the Accept-Ranges header, but how would I implement a Responder that properly handles a Range header? I found a version that had some preliminary support for having the Responder implementation for File handle a Range…
Jasmijn
  • 9,370
  • 2
  • 29
  • 43
3
votes
2 answers

Rocket's State errors with "Attempted to retrieve unmanaged state" when using an explicit lifetime?

When using Rocket's State with omitted lifetimes then a request to the route is handled ok: #[post("/foo")] pub fn foo_handler(db: State) { // ... } However, if explicit lifetimes are provided then Rocket errors on requests with Attempted…
Will Squire
  • 6,127
  • 7
  • 45
  • 57
3
votes
1 answer

How works Json (Form data does not have form content type)

I'm totaly new to rust. I'm trying to create a very simple API with rocket. I have the folowing route that dosn't work and I don't know why. #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; use…
3
votes
1 answer

Cannot move out of borrowed content, with no borrowed content

I'm working on building a REST API using Rust and Rocket. I have an endpoint at which I create a new user, defined as follows: /// View with which to create a user #[post("/users", format = "application/json", data = "")] fn…
coriolinus
  • 879
  • 2
  • 8
  • 18
3
votes
1 answer

Parsing HTTP multipart POST using a struct in Rocket

I want to parse a HTTP POST in Rocket using a struct. Upon submitting the form it fails. I read the body data example and have this code. #[derive(FromForm)] struct ConvertFile { name: String, filename: String } #[post("/submit", format =…
kometen
  • 6,536
  • 6
  • 41
  • 51
2
votes
1 answer

How to debug a "missing field `url`" error with the rocket_db_pools library

I have a Postgres database running at the following url postgresql://postgres:postgres@localhost:5432/my_db I am able to connect to it using pgAdmin and psql psql postgresql://postgres:postgres@localhost:5432/my_db I have the following Cargo.toml…
lblenner
  • 372
  • 2
  • 14
2
votes
1 answer

Rust Rocket, how to Access Data from a Request URI Query

I'm busy working with a Rust Rocket application and I was wondering if it is possible to access the data from a Request URI Query object from inside of a FromRequest implementation. I have an example FromRequest implementation as use rocket; use…
TheLovelySausage
  • 3,838
  • 15
  • 56
  • 106