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

Rust/Rocket: how do I return multiple pages/documents when a user makes an HTTP request?

I'm trying to return multiple documents (index.html, style.css) in an HTTP response when a user makes a single HTTP request. How do I go about doing this? I'm thinking using something like a std::io::File instance to return these, but this hasn't…
VGC3OCJA50
  • 13
  • 2
  • 6
1
vote
1 answer

How to open rust-rocket server to LAN?

I tried rocket, cargo run, access to http://localhost:8000 and looks well. However, I failed to access to http://192.168.developing.pc:8000 from other PC in LAN. I tried http://192.168.developing.pc:8000 in developing PC but was not able to…
v..snow
  • 189
  • 7
1
vote
1 answer

Static lifetime requirements for managed state

I'm having troubles with a managed State with Rocket. This state holds a Database connection and a collection of Cursors on that Database. Each one of theses have a reference on the Database. One of the operations on that state require to create a…
1
vote
1 answer

For the Rust Rocket Framework is it possible to hook up GraphQL to elasticsearch?

I have set up the Rust Rocket web framework and I have been able to make use of the official Elasticsearch Rust crate to set up a client and get documents from the elasticsearch index. However while looking at this example…
zalir
  • 11
  • 1
1
vote
1 answer

How do I use the annotation and micro in the mod of the test scope?

The structure of my code as below. I ran 'cargo run' and it works. But when I ran 'cargo test', I got the errors as below. Could you please tell me why and how can I fix them? error: cannot find attribute get in this scope error: cannot find macro…
Brad C
  • 25
  • 3
1
vote
1 answer

How do I use PickleDB with Rocket/Juniper Context?

I'm trying to write a Rocket / Juniper / Rust based GraphQL Server using PickleDB - an in-memory key/value store. The pickle db is created / loaded at the start and given to rocket to manage: fn rocket() -> Rocket { let pickle_path =…
arturh
  • 6,056
  • 4
  • 39
  • 48
1
vote
1 answer

Unsetting a Session Cookie in Rust with Rocket

I'm so far unable to unset a session through a logout endpoint I have created in Rocket. Below is the code that creates the cookie: impl AuthToken { pub fn from_string(string: String) -> Self { AuthToken(string) } pub fn…
Gabriel Ratener
  • 595
  • 5
  • 20
1
vote
2 answers

How to set up a database connection from environment in Rocket?

I have following working database connection setup for my Rocket app: main.rs: #[database("my_db")] pub struct DbConn(diesel::PgConnection); Rocket.toml: [global.databases] my_db = { url = "postgres://user:pass@localhost/my_db" } I would like to…
SS_Rebelious
  • 1,274
  • 2
  • 19
  • 35
1
vote
1 answer

Does Rocket have something like Flask's blueprints?

In Python's Flask, there is a feature called blueprints, SO even got a great overview of it. Does Rocket have something similar, so I can better structure my code and not mount each route in main?
keddad
  • 1,398
  • 3
  • 14
  • 35
1
vote
2 answers

Can one implement/derive Serialize on an enum without #[derive(Serialize)]?

I'm using rust + rocket + diesel (orm) + serde_derive to make a rest api. Currently, I'm dealing with error handling for the api if diesel fails to insert a user for whatever reason. It looks like this: pub fn create(user: InsertableUser,…
SRugina
  • 129
  • 9
1
vote
1 answer

Rust function return type with lifetime value

I'd like to implement the Responder trait for my Hero structure, but the following method signature (respond_to): use rocket::{http::Status, response::Responder, Request, Response}; use serde::{Deserialize, Serialize}; #[derive(Serialize,…
Nambi
  • 2,688
  • 8
  • 28
  • 37
1
vote
1 answer

How to respond with a different value depending on the state of the Rocket server?

I want to respond with a different value to "the same request" depending on the state of server. My expectation is that these responses will happen in a loop: Someone sends a GET / request, it responds with "Hello, World!". Then they send a GET /…
lenna_kun
  • 43
  • 5
1
vote
1 answer

Rocket.rs: Optional PathBuf has no matching routes

I'm creating a portfolio website and some projects have static HTML demos which I'd like to serve according to the ID in the URL. The route looks like this: #[get("/demo//")] fn site_demo(id: usize, pathbuf: Option) ->…
user7775047
1
vote
1 answer

How to return a State value from a Rocket endpoint?

I'm storing data from an external service in a local cache and I want to create an endpoint to return data currently in the cache. #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; use rocket::{Route, State}; use…
Varkal
  • 1,336
  • 2
  • 16
  • 31
1
vote
2 answers

How does a Rust PathBuf prevent directory traversal attacks?

From "A Case for Oxidation: The Rust Programming Language" Sergio Benitez says, Here is a static file server written in Rocket. It is exactly four lines and it guaranteed to not be vulnerable to directory traversal attacks. Those four lines…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468