Git Product home page Git Product logo

realworld-tide's Introduction

RealWorld Example App

Rust/Tide codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

Demo    RealWorld

Overview

This codebase was created to demonstrate a fully fledged backend application built with Rust and tide including CRUD operations, authentication, routing, pagination, and more.

This project attempts to achieve a clear separation between web, domain and persistence logic - loosely along the lines of the ports and adapters architecture.
These three concerns live in separate crates - web, domain and db.
tide is used in the web crate while diesel is the main character of the db crate.
The fourth crate, application, glues the other three together and provides the runnable binary.

Each sub-crate has its own set of tests, with integration tests taking place in the web crate.

You can also exercise the application using Realworld's Postman collection: here.

For more information on how this works with other frontends/backends, head over to the RealWorld repo.

Other frameworks

If you want to get a taste of what it feels like to build a Realworld's implementation using another Rust's web framework, you can reuse the domain and db sub-crate.

You just need to provide an alternative implementation of the web crate leveraging your framework of choice.

Getting started

Setup

Prerequisites

  • Rust 1.39 (see here for instructions)
  • Docker (see here for instructions)
  • Postgres (see here for instructions)

Setup steps

  • Install the diesel CLI:
cargo install diesel_cli --no-default-features --features postgres
  • Launch a local Postgres instance and run SQL migrations:
./scripts/init_db.sh

You are ready to go!

Run tests

Run tests, including DB integration tests

# This will launch a Postgres instance in a docker container.
# You can customise its behaviour using env variables:
# - database name, using POSTGRES_DB
# - user, using POSTGRES_USER
# - password, using POSTGRES_PASSWORD
# - port, using POSTGRES_PORT
# 5434 is the port specified in configuration/test.yml, the test configuration file
POSTGRES_PORT=5434 ./scripts/init_db.sh
# Execute the tests
./scripts/run_tests.sh

Run app and realworld test suite

Run the app

# This will launch a Postgres instance in a docker container.
# You can customise its behaviour using env variables:
# - database name, using POSTGRES_DB
# - user, using POSTGRES_USER
# - password, using POSTGRES_PASSWORD
# - port, using POSTGRES_PORT
# 5433 is the port specified in configuration/development.yml, the default choice
POSTGRES_PORT=5433 ./scripts/init_db.sh
# Launch the application!
cargo run

You can pass the --release flag to squeeze in the last drop of performance.

By default, we look for Postgres on a different port when executing tests - hence you can run the test suite and interact with the application locally without suffering any interference.

If you want to run the "realworld" Postman tests, just execute

git clone https://github.com/gothinkster/realworld
cd realworld/api
APIURL=http://localhost:5000/api ./run-api-tests.sh

Configuration

All configuration files are in the configuration folder.

The default settings are stored in configuration/base.yml.

Environment-specific configuration files can be used to override or supply additional values on top the default settings (see development.yml or test.yml). In a production environment, you could introduce a production.yml to store production-specific configuration values.

Configuration files can also be overriden using environment variables, prefixed with APP: the value of APP_APPLICATION_PORT will have higher priority then application.port in base.yml or development.yml.

All configurable parameters are listed in configuration.rs.

realworld-tide's People

Contributors

colinbankier avatar giesch avatar lukemathwalker avatar oddg avatar senden9 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.