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

Rust-Rocket cannot be compiled

I have set up a rust base project according to the Getting Started page of the rocket-framework: I added this line to my Cargo.toml: rocket = "0.4.10" My main.rs: #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate…
Piwo
  • 1,347
  • 1
  • 12
  • 19
0
votes
0 answers

Periodic tasks in Rust Rocket

I try to build a REST with Rocket, that allows the caller to configure times at which he will be unavailable. Therefore it can either happen, that the unavailability has to be started immediately or I have to store it in a database for later…
Matthias Wimmer
  • 3,789
  • 2
  • 22
  • 41
0
votes
1 answer

How can I proxy/forward data using the Rocket web framework?

I have a list of links I want to serve data randomly from, as if the user manually went to the url themselves. These are not all the same content/file type, however they are all images (jpeg and png) (Ideally I would like to do this with any file…
mmxjohnson
  • 45
  • 6
0
votes
0 answers

How can I setup a logger to auto-append data from HTTP requests?

In my Rust Rocket REST application I use env_logger for logging, which I've configured with something similar to this: env_logger::builder() .format(|buf, record| { writeln!(buf, "{}: {}", record.level(), record.args()) }) …
at54321
  • 8,726
  • 26
  • 46
0
votes
1 answer

Rust - Cannot Access r2d2 pool connection from Rocket State

I am currently learning Rust and Rocket Using Rust 1.54.0+Rocket 0.5.0_rc1+ Diesel 1.4.7 + r2d2 0.8.9 I created a DB Postgres connection pool with r2d2. I want to share the connection pool between requests/Routes, to do that I am trying to use…
Gonzalo
  • 45
  • 8
0
votes
1 answer

Rocket - handle untyped json body with Rocket and okapi

I'm trying to create some simple REST API which will receive some untyped json data for further processing, but I really don't know the structure yet. What I have so far is this: #[openapi] #[post("/api/json-data", format = "json", data =…
Xear
  • 407
  • 1
  • 5
  • 15
0
votes
1 answer

How to return an array of objects queried from external API in Rocket

I'm new to Rust, and wanted to test it out with something simple. The code basically queries an external API and returns the response. In this case, the response is an array of objects. #![feature(proc_macro_hygiene, decl_macro)] #[macro_use]…
kue
  • 341
  • 1
  • 4
  • 11
0
votes
0 answers

Cannot connect to MongoDB in rocket.rs

I am using rocket.rs and trying to connect to my MongoDB database which is listed compatible in the docs https://rocket.rs/v0.4/guide/state/#databases [global.databases] mongodb_logs = { url =…
mooy bot
  • 86
  • 1
  • 6
0
votes
1 answer

how to use methods of struct as handlers in rocket

#[derive(Debug, Clone)] struct Author { dao: T, } impl Author { fn new(dao: T) -> Self { Author { dao: dao } } fn handle_sign_up<'r>(&self, request:…
wangjun
  • 577
  • 1
  • 6
  • 14
0
votes
2 answers

Rocket - Status with json body

I try to return json body with errors in Rust's Rocket. pub fn error_status(error: Error) -> Status { match error { Error::NotFound => Status::NotFound, _ => Status::InternalServerError } } #[get("/user/")] pub fn…
nicram
  • 353
  • 3
  • 7
  • 24
0
votes
1 answer

Cannot move function into another file?

I am having some trouble with moving a function into a separate file when using the rocket library. I am able to compile and run the getting-started-example from rockets web page, like this: // main.rs #![feature(proc_macro_hygiene,…
SørenHN
  • 566
  • 5
  • 20
0
votes
0 answers

How to retrieve values from tera template by rocket framework?

I need to get values from input form of tera template to rocket code. How can I do that? Here is the template: {% extends "base" %} {% block content %}

Task:

    {{task}}

0
votes
1 answer

Diesel and Rocket imports break as soon as I include a file

I have the file "user.rs" that has the struct of a postgres database table. Whenever I try to include it in my main.rs file (A Rocket web project), all of the Diesel "stuff" can't resolve. Here is my user.js file: use super::schema::users; pub mod…
UnicornsOnLSD
  • 631
  • 6
  • 24
0
votes
1 answer

Rocket couldn't parse JSON body

I am trying to make a POST request with Postman to my Rust API: #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; #[macro_use] extern crate serde_derive; use rocket_contrib::json::{Json, JsonValue}; #[derive(Serialize,…
0
votes
1 answer

How to fix unused lifetime?

While trying to create a simple webserver in Rocket, I ran into the problem that I wanted to redirect or send html data, depending on certain conditions as follows: #[post("/test/")] // This doesn't work Redirect and Html are different…