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

How to retrieve HTTP headers from a request in Rocket?

I would do something like this using flask in Python: @app.route('/login/', methods=['POST']) def login(): token = request.headers["token"] I cannot figure out how to access the token header and store it as a String…
Dilec Padovani
  • 149
  • 1
  • 8
6
votes
1 answer

How to create an endpoint with a Rust keyword as a query dynamic parameter?

I use the Rocket library and I need to create an endpoint which contains the dynamic parameter "type", a keyword. I tried something like this but it does not compile: #[get("/offers?")] pub fn offers_get(type: String) -> Status { …
sbagin13
  • 105
  • 4
6
votes
2 answers

How to parse multipart forms using abonander/multipart with Rocket?

This might be useful for me: I have no idea how you're meant to go about parsing a multipart form besides doing it manually using just the raw post-data string as input I will try to adjust the Hyper example but any help will be much…
rofrol
  • 14,438
  • 7
  • 79
  • 77
5
votes
1 answer

Retrieve raw file content from form-data

I'm working with Rust and Rocket. I have an endpoint to upload one file at a time with form-data: use rocket::form::{Form, FromForm}; use rocket::fs::TempFile; use std::ffi::OsStr; use std::path::{Path}; use uuid::Uuid; #[post("/file_upload",…
Emille C.
  • 315
  • 2
  • 15
5
votes
0 answers

Can't get Rocket's EventStream! to work with borrowed values

This is a pretty specific question related to the Rocket crate. I'm not sure if this is an issue with the crate or if I'm just doing something plain wrong. I'm not the best with lifetimes and macros. I'm trying to setup an SSE connection, and I want…
Taztingo
  • 1,915
  • 2
  • 27
  • 42
5
votes
3 answers

The trait `diesel::Connection` is not implemented for `DbConnection`

I'm trying to add a postgres database to a rocket app using diesel. My main.rs file looks like this, but gives the error "the trait diesel::Connection is not implemented for DbConnection" at .get_result(connection) #[macro_use] extern crate…
Michael Evans
  • 971
  • 1
  • 13
  • 30
5
votes
1 answer

Rust/Rocket: the trait `serde::ser::Serialize` is not implemented for struct

I'm trying to make a simple endpoint using Rocket. My Cargo.toml has these dependencies: [dependencies] rocket = "0.4.2" rocket_codegen = "0.4.2" rocket_contrib = "0.4.2" main.rs looks like: #[macro_use] extern crate rocket; use…
cbll
  • 6,499
  • 26
  • 74
  • 117
5
votes
1 answer

Compiling Rocket in Bazel

I'm attempting to get a working prototype of the following scenario: Language: Rust (rustc 1.45.0-nightly (ad4bc3323 2020-06-01)) Framework: Rocket v0.4.4 Build Tool: Bazel Platform: Mac OS X / Darwin x64 Running bazel build //web-api yields the…
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
4
votes
1 answer

Why is Rocket's `Json` type not found in the `content` module?

Today I found that a project that previously worked no longer compiles. Here is a minimal example that reproduces my sudden error: use rocket::{get, launch, routes}; use rocket::response::content; #[get("/health")] pub fn health() ->…
spark
  • 663
  • 1
  • 5
  • 18
4
votes
1 answer

Cannot set expire in private cookie Rocket-Rust

I'm trying to setting expire in private Cookie in Rust (Rocket Framework version 0.5.0-rc.1) using rocket::http::Cookie. In rocket add_private doc I read: Unless a value is set for the given property, the following defaults are set on cookie before…
P91
  • 43
  • 3
4
votes
3 answers

How to spin up a rocket server along with other stuff?

Basically I want to have a single process handling multiple things at the same time (specifically want to have an http endpoint for monitoring a non-http service), but it seems I'm being caught up in Rocket depending on a rocket-specific tokio…
jack
  • 573
  • 4
  • 12
4
votes
1 answer

How can I make a postgres pool connection global in rocket.rs and make FromRequest custom guards asyncable?

I am making an authorization system which will implement the FromRequest trait from the web framework rocket, which is needed to make custom guards. The first problem I have gone into is how I have to make the connection global. Should I cast it as…
tsu_katana
  • 47
  • 1
  • 5
4
votes
1 answer

how to use rocket_contrib Json?

I'm a beginner with rust and Rocket. I'm trying to understand Rocket by reading the examples in the official repositories. Therefore, there is an example called content_type, and there is a description such as // NOTE: In a real application, we'd…
musako
  • 897
  • 2
  • 10
  • 26
4
votes
1 answer

Rendering a template to string in rust rocket

I'm writing a small website in rust rocket. I'm using handlebar templates, and the way you return a Template form a handler is quite convenient. But I also want to use my template engine for emails I'm sending out. The problem is, that Templates in…
kratenko
  • 7,354
  • 4
  • 36
  • 61
4
votes
1 answer

Rocket's Responder trait is not implemented for Result

I've recently started learning Rust, and I'm currently trying to create a small API; I've made my own struct for an API Response and enum for an Error: // API Response Structure pub struct ApiResponse { pub body: JsonValue, pub status:…
kernel_dev
  • 143
  • 1
  • 8
1
2
3
18 19