Skip to content

rfrazier716/warp_crud

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Warp Todos

Basic todo list app with session support using Rust, Warp, and MongoDB.
View Demo

Table of contents generated with markdown-toc

About The Project

This project spawned from my reading Luca Palmeiri's excellent book Zero To Production in Rust. While his book focuses on using Actix and Postgres, I was more interested in learning MongoDB and found myself drawn to Warp due to the Filter Traits.

At the same time I was also reading through a Real Python Article on setting up a REST API. I decided to mimic my routes after the article's, which allowed me to copy their front-end code and focus on the back-end.

Fast Forward a couple months and I was ready to try my hand at deploying the webserver to Heroku or similar, but was mortified at the thought of giving random strangers on the internet write access to a database that other visitors would see! The way around this was to implement session cookies, so each user only saw their own sessions. While I was at it I also changed the "People API" to a general todo list, as I have no idea who would want to make lists of people sorted by date.

Most of the code structure comes from Luca's book and blog posts on LogRocket's Blog, I've tried to credit any relavent ones in the Acknowledgements section.

Features

  • Create up to a whopping 10 todo items which can be updated and deleted with the press of a button!
  • synchronous 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
  • Session cookies to Isolate users
  • Built with the warp framework, which builds on top of hyper.
  • All the security benefits of Rust

Built With

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.

  • Docker -- Required to run integration tests and start a local MongoDB instance.

Installation

  1. Clone the Project
    git clone https://github.com/rfrazier716/warp_crud.git; cd warp_crud
  2. Build the Code
    cargo build

Usage

The Webserver relies on an active MongoDB instance which acts as a persistant data store. to start a local instance use the docker compose located in the tests/docker directory

cd tests/docker
docker compose up

Starting the Server

To launch the web server navigate to the base directory and run.

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

You can customize the startup configuration by editing the files in config and setting the RUN_ENV environment variable Accordingly. e.g. RUN_ENV="Production" cargo run will launch the webserver with the production configuration. Config files must be serializable into a Settings struct (see config.rs).

Any field in the settings struct can be provided by the command line by using the "EA" previx and using a double underscore for nested fields. e.g. to set settings.database.uri use the environment variable EA_DATABASE__URI.

License

This Code is published under the MIT license.

Contact

Ryan Frazier - @fotonixandgizmo - Ryan@Fotonixx.com

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

Acknowledgements

About

A basic example of a CRUD api with warp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published