Section III - module
To create the module, create a new file named data_service.rs in the /src directory.
Since we will be using the actix-web and couchdb functionality, we need to declare our use statement at the top of the file.
use super::*;
use actix_web::{App, http, HttpRequest, HttpResponse};
use actix_web_httpauth::extractors::basic::BasicAuth;
use super::couchdb::{CouchDB};
use std::thread;Tests
Add the following unit test to the bottom of the module to cover the basic funcitonality.
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_service_root() {
assert_eq!(get_service_root(), format!("/data/{}", VER));
}
}Code
We start by defining our modular variables.
IMPORTANT You will need to create a
consumingdatabase in CouchDB
And then our generic supporting functions that provide the resource path.
Next, we define the supportive function that the serivce will call.
Lastly, we define the funciton that will provide the App object to the executable.
Now is a good time to rerun the
cargo testcommand to ensure all your tests still pass.
Last updated
Was this helpful?