Section IV - executable
Once we have created our service and all the tests have passed, we are ready to build out the executable and run it.
We start by first adding the log
and env_logger
crates to the Cargo.toml manifest.
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
Open your browser and navigate to the URL: http://localhost:7999/hello/v1/. 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.
To stop the service, use ctrl
+ c
.
Running using the executable.
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.
Last updated
Was this helpful?