Skip to content

A Rust (Tide) API with a containerized PostgreSQL database.

License

Notifications You must be signed in to change notification settings

dgonzo27/rust-tide-pg

Repository files navigation

Rust + Tide + PostgreSQL

Rust Tide Docker Pre-Commit Bash GitHub_Actions

This repository contains a Rust (Tide) API with a containerized PostgreSQL database. Additionally, the repository contains a Rust test suite for integration testing API routes as it relates to CRUD operations and transactions against the containerized database.

Table of Contents

Getting Started

This section provides supporting steps and documentation for developing locally.

Prerequisites

Before jumping into the code, there are a few prerequisites.

  1. Local development should be done from a UNIX-based machine - use Linux, MacOS, or WSL2 if you're on a Windows machine.

  2. GitHub access should be managed through an SSH key in your UNIX environment. If you're unfamiliar with this process start here.

  3. Docker Desktop should be installed on your machine for local development. If you're on Windows, configure your settings to enable Docker Desktop in WSL2.

  4. pre-commit should be installed globally on your machine for linting and validating your code prior to pushing up to GitHub.

  5. Rust should be installed globally on your machine for compiling and running code.

  6. Optionally, the Rust-Analyzer extension can be installed in VS Code for a better development experience.

Local Development Guide

This project uses a variation of scripts to rule them all.

  1. Clone the repository (if this is your first time).

    git clone git@github.com:dgonzo27/rust-tide-pg.git
  2. Navigate into the repository directory.

    cd rust-tide-pg
  3. Ensure pre-commit is enabled for this repository.

    pre-commit install
  4. You might need to give yourself access to the scripts for running this project.

    chmod +rwx scripts/clean
    chmod +rwx scripts/compile
    chmod +rwx scripts/database
    chmod +rwx scripts/format
    chmod +rwx scripts/server
    chmod +rwx scripts/setup
    chmod +rwx scripts/stop
    chmod +rwx scripts/test
  5. Run the project.

    scripts/setup
  6. From a new terminal tab or an API client of your choice, test some API routes.

    # create a new user
    curl -v -d '{"username": "my_username", "first_name": "My", "last_name": "Username", "password": "password"}' http://localhost:8080/api/v1/auth/signup
    
    # login as the new user
    curl -v -d '{"username": "my_username", "password": "password"}' http://localhost:8080/api/v1/auth/login
    
    # using the returned access token, test the movie routes
    curl -H "Authorization: Bearer <access_token_here>" -v -d '{"title": "test", "description": "test"}' http://localhost:8080/api/v1/movies
    curl -H "Authorization: Bearer <access_token_here>" -g http://localhost:8080/api/v1/movies
    curl -H "Authorization: Bearer <access_token_here>" -g http://localhost:8080/api/v1/movies/1
    curl -H "Authorization: Bearer <access_token_here>" -X PUT -d '{"id": 1, "title": "new title", "description": "new desc"}' http://localhost:8080/api/v1/movies/1
    curl -H "Authorization: Bearer <access_token_here>" -X DELETE http://localhost:8080/api/v1/movies/1
  7. Stop the Rust server from your original terminal tab.

    ctrl + c
  8. Run the test suite.

    scripts/test
  9. Stop the development environment.

    scripts/stop

Other Commands

  1. Format and validate all files.

    scripts/format
  2. Clean your database, removing any existing volumes and images (data).

    scripts/clean

Need Support?

File an issue via GitHub Issues.

Reporting Security Vulnerabilities and Security Bugs

Security vulnerabilities and bugs should be reported privately, via email, to the maintainers of this repository. Please contact Dylan Gonzales. For more information, visit the security guidelines.

Contributing

Before contributing to this repository, please review the code of conduct.

Contributions and suggestions are welcomed. However, there is a level of responsibility placed on the contributor to follow best-practices, provide thorough testing, follow the branching strategy, use the pull request template, and maintain a positive and coachable attitude when receiving feedback or questions on your code. For more details on these responsibilities, please visit the contributing guide.

When contributing, you are granting the maintainers of this repository the rights to use your contribution(s).

About

A Rust (Tide) API with a containerized PostgreSQL database.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project