An Async Warp Webserver Template With MongoDB Connection
View Demo
·
Report Bug
·
Request Feature
More details coming soon!
In short, this is a Rust webserver template using Warp and MongoDB to help speed up API development.
- Turnkey Asynchronous Webserver with runtime configuration through config files and environment variables.
- Cached CI/CD pipeline with CircleCI including the following jobs:
- Formatting check with
cargo fmt - Linting Check with
cargo clippy - vulnerability check with
cargo audit - unittests run on every commit
- Integration tests with database queries that run on commits to
mainordevelopment
- Formatting check with
- Built with the warp framework, which builds on top of hyper.
- All the security benefits of Rust
To get a local copy up and running follow these simple steps.
It's assumed you already have Rust installed on your computer as well as cargo, follow their installation instructions for OS specific installation guides.
- cargo-generate
cargo install cargo-generate
- Docker -- Required to run integration tests
-
Install the project template using Cargo Generate. Note you need to install from the
templatebranch.cargo generate --git https://github.com/rfrazier716/mongo_warp.git --branch template
-
Answer the additional prompts for project names and repository details:
Project Name: This will be the name of the executable and crate. Any hyphens will be converted to underscores code to ensure valid crate names.github username: Is used to generate shields and hyperlinks in the readmerepository name: Is used to generate shields and hyperlinks in the readmeLinkedIn Shield: If set to true, a LinkedIn shield will be included at the top of the repository, otherwise ignored.
This repository is a template to get you up and running with a Rust Webserver faster. For that reason it only includes a basic /health
route that pings the MongoDB instance. To add additional routes and endpoints see the documentation for Warp and MongoDB.
For an example of the template in action, see my warp_crud repository.
The Template includes both unit-tests and integration tests to demonstrate:
- Testing routes using Warp without starting the server
- Running async integration tests on the first available port to allow for parallelization
To run unit tests navigate into the project root directory and run
cargo test --libFor integration tests you'll need to spin up a MongoDB container on port 27017. This is handled by docker and the
docker-compose.yml file in /tests.
cd tests
docker compose upIn addition to the MongoDB image, A mongo-express instance will also
start on localhost:8081.
Once the container is running you can run both Integration and unit tests with Cargo.
cargo testTo launch the web server navigate to the base directory and run. The same MongoDB instance used for health checks must be running or the health check will timeout.
cargo runThe default configuration will start the server on localhost:3030. You can check the health endpoint is running with curl:
$ curl -i localhost:3030/health
HTTP/1.1 200 OK
content-length: 0
date: Tue, 22 Jun 2021 16:57:23 GMTSee the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Licensed under Apache v2.0
Ryan Frazier - @fotonixandgizmo - Ryan@Fotonixx.com
Project Link: https://github.com/rfrazier716/mongo_warp