So this is really a simple issue, but I think I need someone to practically point it out for me because I can't understand how to do what I want to do. I've asked a lot of forums and about it and they've all told me the same, thing, but I just don't get it. Anyway here's what I've been doing. I'm creating a slack bot as an exercise to learn more about actix-web and actix. This bot is supposed to monitor github repositories with github's webhook API and then post messages to slack channels when there is an even that has occurred like a push to a remote branch or a pull request.
Anyway I have been following this tutorial:
It's very thorough and clear on how to set up a rust REST API. My issue comes from the following block of code, which I just cannot figure out:
// invitation_routes.rs
use actix_web::{AsyncResponder, FutureResponse, HttpResponse, Json, ResponseError, State};
use futures::future::Future;
use app::AppState;
use invitation_handler::CreateInvitation;
pub fn register_email((signup_invitation, state): (Json<CreateInvitation>, State<AppState>))
-> FutureResponse<HttpResponse> {
state
.db
.send(signup_invitation.into_inner())
.from_err()
.and_then(|db_response| match db_response {
Ok(invitation) => Ok(HttpResponse::Ok().json(invitation)),
Err(err) => Ok(err.error_response()),
}).responder()
}
The difference with that code is that I don't need a State, my slackbot has no state to modify for the moment. I've been told to just use an empty state, I get that but I'm not sure what to do, especially with a Future. If someone could help me out and rewrite that code with an example that uses no state but still uses Futures and Json. I'm just completely lost on how to do it and searching out there for something similar has proven ineffective.