|1.0.1||May 22, 2023|
#115 in HTTP server
Purpose of this project:
The purpose of this project is to give newcomers to Rust a basic project to learn from, and even use to start their own projects. Starting Rust can be hard. I'm probably a slower learner than most. It has taken me much longer than I would like to admit in order for me to learn everything in these five files. I know that other people are in this position as well. I hope that this repo can serve as a basic example of how these interlocking technologies work together. I know that I probably have not implemented everything according to best practices, but I did the best with what I had. If you would like me to change anything in here, feel free to open a pull request or ask a question.
- The Rust Programming Language
- tokio (Rust runtime)
- tokio-postgres (for connecting to PostgreSQL)
- uuid (Rust crate for UUIDs)
- serde (a crate for working with JSON in Rust)
- actix-web (a framework for creating Rust web services)
How to generate documentation for this project:
cargo doc --open. Running this command will cause Cargo to generate all the relevant documentation for this project. You can also google the documentation via going to docs.rs online and searching for the relevant crate you are interested in.
How to run this project:
- make sure you have a
.envfile with the following values set:
DBNAME. All these values will correlate to how you set up PostgreSQL.
- make sure you have
docker composeinstalled (the current version as of writing this is the one lacking the hyphen, so not the
docker compose up -d
- you should be able to hit the routes
localhost:8080/db_testand receive a JSON response.
- if you would like to look at the GUI for PostgreSQL (PgAdmin4), then you can go here:
http://localhost:16543. The username is
email@example.com the password is
testi. to add the PostgreSQL server in PgAdmin4, after logging in click on "Add New Server". On the 'General' tab, name the server anything you would like. Next, select the 'Connection' tab. In place of the 'Host name/address', run this command:
ifconfig | grep inet, and input one of the output ip addresses. For the 'port', input
5440. For 'Maintenance database', input
root. For 'Username', input
root. For 'Password', input
root. Finally, if everything has been input correctly, you should be able to hit the save button on the modal and you should be connected.
- In the
docker_postgres_init.sql, you should see an
INSERTstatement at the bottom of the file. If there isn't any data in the
producttable, then feel free to run that query in PgAdmin. If the
localhost:8080/db_testendpoint was not working before, it may now.
What you can learn from this project:
- how Rust modules work
- how to connect Rust to PostgreSQL
- how to use Actix-Web
- Rust Lifetimes
- a basic way to setup a project
About Jake the Dog
I chose Jake to be the mascot of this project, because Jake is the most dependable friend a person could have. Jake is also very flexible. Flexibility and dependability are two abilities I look for in a webserver.