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

How can I make my Rocket app respond with an error when a request panics?

In my Rocket web application I have a service that reads data from a MySQL database. At some point a NULL value appeared in a VARCHAR field - something my code wasn't expecting and as a result the tx.query_map() method started panicing. I don't like…
at54321
  • 8,726
  • 26
  • 46
1
vote
0 answers

Pass database reference through a FromRequest

I'm using the Rocket web framework in Rust and I have a database pool (DbConn). #[database("redirect-api")] pub struct DbConn(diesel::PgConnection); I have been able to pass DbConn to each route but I am having trouble when trying to pass it to a…
Dzjek R
  • 53
  • 3
1
vote
0 answers

Compiler features conflicting while importing macros

I'm trying to use some of the macros from the diesel crate but they say they have not been imported, even when explicitly imported. I Think the problem is coming from the use the feature decl_macro. This feature is required by rocket in order to use…
Dzjek R
  • 53
  • 3
1
vote
1 answer

Cannot handle a HTTP URL as a query parameter in Rocket

I am using Rocket to create a basic web api to practice and improve my Rust programming skills. Here I got stuck. #[post("/make/")] fn shorten_link(link: String) -> String { // Some other code } The problem is when I post to let's say…
1
vote
1 answer

Serving static files with multiple segments

I'm using Rocket multiple segments to serve static files, by this code: #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; use std::path::PathBuf; use rocket::response::NamedFile; use…
Megidd
  • 7,089
  • 6
  • 65
  • 142
1
vote
1 answer

Rocket testing multipart/data-form fails with 422 (Unprocessable Entity)

I want to test my upload route here. I have one tests that calls this route via the rocket test client but I always get Status { code: 422, reason: "Unprocessable Entity" } as response. However, I cannot figure out what is wrong with my request…
Greeneco
  • 691
  • 2
  • 8
  • 23
1
vote
1 answer

How do I use rocket_contrib::Uuid in a form?

I am using the 0.5.0-dev version of rocket and rocket_contrib. I want to use a Uuid in my form, but I get the following compilation error: the trait `FromFormField<'_>` is not implemented for `rocket_contrib::uuid::Uuid` I do not understand this…
Greeneco
  • 691
  • 2
  • 8
  • 23
1
vote
1 answer

Why is "no crate_relative in serve" when rust rocket_contrib?

I'm trying to learn some rust by my usual method of flailing around and running examples. This page on the rust_contrib api docs makes me think I can serve static files https://api.rocket.rs/master/rocket_contrib/serve/struct.StaticFiles.html like…
BenMaGoo
  • 45
  • 1
  • 8
1
vote
2 answers

impl AsyncRead for tonic::Streaming

I am trying to take the tonic routeguide tutorial, and turn the client into a rocket server. I am just taking the response and converting from the gRPC to a string. service RouteGuide { rpc GetFeature(Point) returns (Feature) {} rpc…
matanmarkind
  • 219
  • 3
  • 13
1
vote
1 answer

How to use rocket::response::Flash in a tera template

I am currently re-writing a web application built in python/flask that uses flashes as so: {% with flashes = get_flashed_messages() %} {% if flashes %}
    {% for message in flashes %}
  • {{ message }} …
banksdev
  • 198
  • 1
  • 1
  • 8
1
vote
0 answers

How do I return a status code other than 500 when an error occurs in Rocket?

I'm trying to make my Rocket backend return HTTP 400 when the user enters a password that is too short. When I try to send a request with a password that is too short, the request panics and returns 500 since I'm using the Err() function, which…
UnicornsOnLSD
  • 631
  • 6
  • 24
1
vote
1 answer

diesel.rs and rocket.rs: don't understand why it wants a databases table

I'm new to Rust, and I'm having an issue I can't wrap my head around. My Cargo.toml looks like this: [dependencies] rocket = "0.4.6" rocket_codegen = "0.4.6" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" [dependencies.diesel] version =…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
1
vote
1 answer

Trying to implement rocket_cors CorsOptions on a rust api

I'm new to rust and I'm using rocket to create a simple CRUD API that I later would like to put on an AWS EC2 bucket. I've got one or two basic routes and I wanted to start to implement CORS so a react app can call my API. I've tried multiple…
1
vote
1 answer

How do I pass a database connection to Rocket endpoints and functions?

My web application has a REST API via Rocket, connects to a MySQL database, and there's a single endpoint. I cannot figure out how to access the database connection inside the controller: #![feature(decl_macro)] #[macro_use] extern crate…
cbll
  • 6,499
  • 26
  • 74
  • 117
1
vote
1 answer

React app with Rocket backend giving ECONNREFUSED when using proxy

I'm trying to make a web app using rocket for the backend and react for the frontend. However, when I try to make a proxy I keep getting rayk@pop-os:~/repos/homrs/frontend$ curl http://localhost:3000/api Proxy error: Could not proxy request /api…
Ray Kochenderfer
  • 333
  • 1
  • 6
  • 15