Skip to content

A simple To Do REST API application using Rocket to introduce Rust.

Notifications You must be signed in to change notification settings

alpaslaneldemir/basic-rocket-web-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Rocket Web Server

This application was made part of an introductory video for Rust. The video included an overview of some Rust syntax, along with the implementation of this simple To Do REST API.

The video can be seen on YouTube

Installing Rust

The easiest way to install Rust is by using rustup, a Rust version manager. Follow the instructions on the rustup site for your operating system.

By default, rustup will install the latest stable verison of Rust. Rocket currently requires a nightly version of Rust. When you're in the directory containing this repository's code, rustup will look in the rust-toolchain file and automatically install and use the correct Rust version for you. Test this out with:

$ rustc --version

If that does not work for any reason, you can set the directory to use nightly by running the follow:

$ rustup override set nightly

Useful toolchain extentions

Recommended extension to install that watching and auto-reloading of the application through the use of cargo watch -x run. more details

$ cargo install cargo-watch

Recommended extension to install that provides cargo add, cargo rm, and cargo upgrade for adding and removing packages against https://crates.io/ more details

$ cargo install cargo-edit

Optional extension to install that provides cargo expand which outputs pre-processed code such as what macros generate. more details

$ cargo install cargo-expand

Useful VSCode extention

Recommended VSCode extension to give extremely useful tooltips and highlighting is rust-analyzer

Compiling and Starting the Server

Built using Cargo, Rust's package manager and build tool.

To compile for development, run:

$ cargo build

which will create a binary in target/debug that you can run with:

$ ./target/debug/basic-rocket-web-server

You can compile and run with one command by using:

$ cargo run

If you installed cargo-watch, you can have cargo automatically rebuild and run the application on file changes within the project with the following command. Note that the .gitignore file will be respected and your application will not be rebuilt for changes to any file or folder listed there.

$ cargo watch -x run

When compiling for performance testing, build in release mode by using:

$ cargo build --release

which will create the corresponding binary in target/release:

$ ./target/release/basic-rocket-web-server

Similarly, you can do this in one step with:

$ cargo run --release

The server will, by default, start an HTTP API server on port 8000 and will only be accessible as localhost unless running in release mode.

Further Reading

Rust Language

About

A simple To Do REST API application using Rocket to introduce Rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%