We place the extern crate declarations and use declarations for these crates at the top of our lib.rs file (so that they are ben shared in the project).
Now that we have the dependent crates included and declared, we add a new method named service after the index() method in the hello_world.rs file in the /src directory to provide a runtime application that references the index90 method for the defined resource path referenced by the get_service_path() method.
Make sure all your tests are still passing by using the cargo test command.
We are now ready to start the RESTful service. There are 2 ways to start the service.
Running using cargo run command
PS C:\workspace\rust-daas> cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.37s
Running `target\debug\hello_world.exe`
[2019-10-23T14:40:08Z INFO actix_web::middleware::logger] 127.0.0.1:65211 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[2019-10-23T14:40:08Z INFO actix_web::middleware::logger] 127.0.0.1:65211 "GET /hello/v1/ HTTP/1.1" 200 12 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36" 0.000000
To stop the service, use ctrl + c.
Running using the executable.
PS C:\workspace\rust-daas> cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.37s
Whenever you use the cargo build command, it places the created executable in the target/debug directory with the same name that was defined in the Cargo.toml manifest, (e.g.: C:\workspace\rust-daas\target\debug\hello_world.exe)
Since it is an executable, simple run the executable from the command terminal, and make the same URL call from the browser.
C:\workspace\demo\rust-daas\target\debug>hello_world.exe
[2019-10-23T14:49:19Z INFO actix_web::middleware::logger] 127.0.0.1:65360 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36
[2019-10-23T14:49:19Z INFO actix_web::middleware::logger] 127.0.0.1:65360 "GET /hello/v1/ HTTP/1.1" 200 12 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36" 0.000948
Open your browser and navigate to the URL: . You should see the message Hello World! On the command line, you will notice that the calls are being logged and printed to the consule.