Use POST like a GET? #2669
Unanswered
darksylinc
asked this question in
Questions
Replies: 1 comment 4 replies
-
Simply changing put to post worked for me. #[rocket::post("/auth/authenticateUser?<username>&<password>&<game>")]
async fn authenticate_user(
username: Option<&str>,
password: Option<&str>,
game: Option<&str>,
) -> Result<&'static str, ()> {
println!("{:?}", username);
println!("{:?}", password);
println!("{:?}", game);
return Ok("");
} I used this curl request to verify the prints are correct: curl -X POST 'https://localhost/auth/authenticateUser?username=test&password=1234&game=four' |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
Rocket supports the following:
And it works exactly as I want and expect.
However what I'm having trouble with (and I'm not sure if it's possible) is what happens if the 3 parameters are sent through POST instead of GET.
I managed the following to work:
I confirmed it works correctly. I haven't yet played enough with this, I probably want to add a
Strict<>
.However what I want to ask: is there a way to tell Rocket to use the first way? I would like to avoid the hassle of defining a struct for each POST argument for each function (the API is already like this).
Basically something like the following (not valid code):
I read in the documentation that Rocket has a
_method
workaround that sounds like what I want:However:
So the TL;DR:
_method
alternative meant to achieve this?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions