Skip to content

rfrazier716/mongo_warp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Mongo Warp

An Async Warp Webserver Template With MongoDB Connection
View Demo · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

More details coming soon!

In short, this is a Rust webserver template using Warp and MongoDB to help speed up API development.

Features

  • 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 main or development
  • Built with the warp framework, which builds on top of hyper.
  • All the security benefits of Rust

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

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

Installation

  1. Install the project template using Cargo Generate. Note you need to install from the template branch.

    cargo generate --git https://github.com/rfrazier716/mongo_warp.git --branch template
  2. 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 readme
    • repository name: Is used to generate shields and hyperlinks in the readme
    • LinkedIn Shield: If set to true, a LinkedIn shield will be included at the top of the repository, otherwise ignored.

Usage

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.

Running Tests

The Template includes both unit-tests and integration tests to demonstrate:

  1. Testing routes using Warp without starting the server
  2. Running async integration tests on the first available port to allow for parallelization

Unit Tests

To run unit tests navigate into the project root directory and run

cargo test --lib

Integration Tests

For 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 up

In 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 test

Starting the Server

To 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 run

The 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 GMT

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Licensed under Apache v2.0

Contact

Ryan Frazier - @fotonixandgizmo - Ryan@Fotonixx.com

Project Link: https://github.com/rfrazier716/mongo_warp

Acknowledgements

About

Going through Zero to Production in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages