Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.

Overview

RealWorld Example App

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

(2021/05/13) This codebase is currently unmaintained, and I am not interested in maintaining it. This relies on an old version of Actix -- developers who want to learn Actix should probably read the latest docs at the Actix website.

This codebase was created to demonstrate a fully fledged fullstack application built with Actix including CRUD operations, authentication, routing, pagination, and more. CORS, however, is not yet added.

This implementation is not reviewed. See the Contributing section below.

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

How it works

This is an application written in Rust that utilizes Actix for developing the backend web service that powers the RealWorld application.

You can view a full list of crates being used in Cargo.toml, but here are some of the main ones of note:

  • Actix - a powerful Actor framework
  • Chrono - a Date and Time library for Rust
  • Failure - a system for creating and managing errors in Rust
  • Futures - Zero-cost Futures in Rust
  • jsonwebtoken - Create and parses JWT (JSON Web Tokens)
  • libreauth - a collection of tools for user authentication
  • Serde - a framework for serializing and deserializing Rust data structures efficiently and generically
  • Uuid - Generate and parse UUIDs
  • validator - Simple validation for Rust structs

Getting started

  • Install Rust
  • Install PostgreSQL if you don't have it already.
  • Install the Diesel CLI with the postgres feature enabled.
  • Clone this repo to a folder on your computer.
  • Copy (cp) .env.example to .env within this directory, and change the environment variables accordingly to your system.
  • Setup your database by running diesel database setup. Make sure it has completed successfully.
  • Build this project with cargo build. You are welcome to compile with --release if you'd like.
  • Run with cargo run.
  • The API URL will be whatever the BIND_ADDRESS value is in .env with the /api path included e.g. https://127.0.0.1:3000/api. Set it as such in your REST client (Postman, Insomnia, etc.), import the postman collection and start testing it out!

Contributing

Feel free to take a look at the current issues in this repo for anything that currently needs to be worked on.

You are also welcome to open a new issue if you see something is missing or could be improved upon.

Comments
  • Missing field(s) in JSON payload should return a more detailed error message

    Missing field(s) in JSON payload should return a more detailed error message

    https://www.reddit.com/r/rust/comments/b1r9jn/implementation_of_the_realworld_backend_in_actix/eio4prd/

    This will be of some interest:

    https://docs.rs/actix-web/0.7.18/actix_web/dev/struct.JsonConfig.html

    wontfix 
    opened by fairingrey 7
  • Deserialize(Error(

    Deserialize(Error("EOF while parsing a value", line: 1, column: 0))

    http://127.0.0.1:8088/api/users My Json request is

    "user": { "username": "fdfdfddf", "email": "[email protected]", "password": "fddf3123" }
    }
    

    but got this error, it is weird. anyone can tell why this happens?

    opened by pengw00 2
  • Upgade actix and actix-web

    Upgade actix and actix-web

    Fixes https://github.com/fairingrey/actix-realworld-example-app/issues/13.

    I upgraded actix = "0.8.3" and actix-web = "1.0.7". The most part was rather mechanic. I only needed to refactor main and pub fn create() -> App<AppState> a bit, because the App<T, B> type is rather unergonomic. The result is app/mod.rs/start.

    I also changed a tiny bit of functionality: When FRONTEND_ORIGIN is not set, the response now contains Access-Control-Allow-Origin: '*' instead of staying silent.

    @fairingrey ping: If you can find some time it'd be awesome to get some feedback

    opened by geropl 2
  • Finish the rest of application logic

    Finish the rest of application logic

    Whatever in code that says unimplemented!() still has yet to be implemented, though it's pretty much all message handling logic for DbExecutor.

    https://github.com/fairingrey/actix-realworld-example-app/search?q=%22unimplemented%21%28%29%22&unscoped_q=%22unimplemented%21%28%29%22

    Once that's finished, the plan is to eventually submit it to the Rust community for advice and if any refactoring needs to be done :smile:

    help wanted 
    opened by fairingrey 1
  • Errors seem to require a special JSON format

    Errors seem to require a special JSON format

    Errors seem to require a special JSON format, detailed here in the API spec: https://github.com/gothinkster/realworld/tree/master/api#errors-and-status-codes

    {
      "errors":{
        "body": [
          "can't be empty"
        ]
      }
    }
    

    This is the file where custom errors are generated, so we'll have to make some changes here such that .json(message) takes in a proper object that can be serialized in such a format. More info on that function can be found here, but it takes in a type that impl's Serialize.

    FWIW, validation errors does not currently offer any default implementation of Serde's Serialize so we'll have to implement it on our own as described at https://serde.rs/impl-serialize.html or use an existing type that they provide (see my comment below).

    enhancement help wanted invalid 
    opened by fairingrey 1
  • Actix server + DNS

    Actix server + DNS

    Hello.

    I've been scouring for a solution to this, but I can't seem to find one. Maybe I'm understanding this wrong cause I'm pretty new to rust.

    How could I connect the actix server to a dns? As it is at the moment it seems that the only way to access the server's api is through an application running on the same machine.

    opened by kiipri 0
  • refactor database/models

    refactor database/models

    Changes to a lot of the old database migrations. Some fields use UUID as primary key now, and junction tables use composite primary keys when necessary.

    Also changed the db/app model to reflect the Actor model architecture more -- will finish this soon

    opened by fairingrey 0
  • Actix-web 4 support

    Actix-web 4 support

    Hello,

    If you do not want to maintain this repo anymore can you transfer ownership to myself or add me as a collaborator. I've upgraded everything to the latest and have a working branch that will be useful for the community. Please let me know.

    Thanks! thad

    opened by flomang 0
  • Bump diesel from 1.4.2 to 1.4.6

    Bump diesel from 1.4.2 to 1.4.6

    Bumps diesel from 1.4.2 to 1.4.6.

    Release notes

    Sourced from diesel's releases.

    1.4.6

    Fixed

    • Fixed a use-after-free issue in the QueryableByName implementation of our Sqlite backend
    • Updated several dependencies

    1.4.5

    Fixed

    • Update several dependencies
    • Fixed an issue where transactions that would fail to commit would leave the connection in a broken non-committed non-rolled-back state.
    • Fix a bug that result in leaking sockets/file descriptors on failed connection attempts for postgresql
    • Fix an incompatibility with newer libmysqlclient versions
    • Remove some potential harmful usages of mem::uninitialized

    1.4.4

    Fixed

    • Update several dependencies
    • Fixed a bug with printing embedded migrations

    As part of this release also updated versions of migration_internals and migration_macros are published.

    1.4.3

    Fixed

    • Updated several dependencies
    • Fixed an issue where the postgresql backend exploits implementation defined behaviour
    • Fixed issue where rustdoc failed to build the documentation
    • diesel_derives and diesel_migrations are updated to syn 1.0
    Changelog

    Sourced from diesel's changelog.

    [1.4.6] - 2021-03-05

    Fixed

    • Fixed a use-after-free issue in the QueryableByName implementation of our Sqlite backend
    • Updated several dependencies

    [1.4.5] - 2020-06-09

    Fixed

    • Update several dependencies
    • Fixed an issue where transactions that would fail to commit would leave the connection in a broken non-committed non-rolled-back state.
    • Fix a bug that result in leaking sockets/file descriptors on failed connection attempts for postgresql
    • Fix an incompatibility with newer libmysqlclient versions
    • Remove some potential harmful usages of mem::uninitialized

    [1.4.4] - 2020-03-22

    Fixed

    • Update several dependencies
    • Fixed a bug with printing embeded migrations

    [1.4.3] - 2019-10-11

    Fixed

    • Updated several dependencies
    • Fixed an issue where the postgresql backend exploits implementation defined behaviour
    • Fixed issue where rustdoc failed to build the documentation
    • diesel_derives and diesel_migrations are updated to syn 1.0
    Commits
    • b0c8e99 Release diesel 1.4.6
    • ae72835 Merge pull request #2663 from weiznich/bugfix/fix_use_after_free
    • cead1a3 Downgrade max bigdecimal version as the new version is incompatible
    • 2a612f0 Run cargo fmt
    • d699f14 Bump some dependencies
    • d219211 Address review comments
    • d413328 Fix a use-after-free bug in our Sqlite backend
    • 8e9e639 More fixes for mysql setup
    • 453cfb8 Remove clippy from ci on release branch
    • d856d35 Fix mysql instalation on macos
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump net2 from 0.2.33 to 0.2.37

    Bump net2 from 0.2.33 to 0.2.37

    Bumps net2 from 0.2.33 to 0.2.37.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump miow from 0.2.1 to 0.2.2

    Bump miow from 0.2.1 to 0.2.2

    Bumps miow from 0.2.1 to 0.2.2.

    Commits
    • 6fd7b9c Bump version to 0.2.2
    • 550efc2 Merge branch 'fix-sockaddr-convertion-v0.2.x' into 0.2.x
    • ca8db53 Stop using from_ne_bytes to be compatible with Rust < 1.32.0
    • 3e217e3 Bump net2 dep to 0.2.36 without invalid SocketAddr convertion
    • 27b77cc Adapt to winapi 0.2
    • 2783715 Safely convert SocketAddr into raw SOCKADDR
    • f6662ef Clarify wording of license information in README.
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump actix-service from 0.4.2 to 1.0.6

    Bump actix-service from 0.4.2 to 1.0.6

    Bumps actix-service from 0.4.2 to 1.0.6.

    Release notes

    Sourced from actix-service's releases.

    actix-service: v1.0.6

    Fixed

    • Removed unsound custom Cell implementation that allowed obtaining several mutable references to the same data, which is undefined behavior in Rust and could lead to violations of memory safety. External code could obtain several mutable references to the same data through service combinators. Attempts to acquire several mutable references to the same data will instead result in a panic.

    Big thanks to @​Shnatsel, @​dunnock and @​Nemo157 for working towards this fix. 🎉

    actix-server: v1.0.4

    • Update actix-codec to 0.3.0.
    • Workers must be greater than 0. #167

    #167: actix/actix-net#167

    actix-server: v1.0.3

    [1.0.3] - 2020-05-19

    Changed

    • Replace deprecated net2 crate with socket2 #140

    #140: actix/actix-net#140

    actix-testing: v1.0.1

    [1.0.1] - 2020-05-19

    • Replace deprecated net2 crate with socket2

    • Remove unused futures dependency

    bytestring: v1.0.0

    • Update bytes dependency to 1.
    • Add array and slice of u8 impls of TryFrom up to 32 in length.
    • Rename get_ref to as_bytes and rename into_inner to into_bytes.
    • ByteString::new is now a const fn.
    • Crate is now #[no_std] compatible.

    actix-codec: v0.5.1

    • Logs emitted now use the tracing crate with log compatibility. #451
    • Minimum supported Rust version (MSRV) is now 1.49.

    #451: actix/actix-net#451

    actix-codec: v0.5.0

    • Updated tokio-util dependency to 0.7.0. #446

    #446: actix/actix-net#446

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump socket2 from 0.3.9 to 0.3.19

    Bump socket2 from 0.3.9 to 0.3.19

    Bumps socket2 from 0.3.9 to 0.3.19.

    Changelog

    Sourced from socket2's changelog.

    0.4.5

    Changed

    Added

    Fixed

    0.4.4

    Fixed

    • Libc v0.2.114 fixed an issue where ip_mreqn where was not defined for Linux s390x.

    0.4.3 (yanked)

    Added

    0.4.2

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Allen
Rustyboo. I like working with backend web stuff, in particular with async/await.
Allen
A (flash) message framework for actix-web. A port to Rust of Django's message framework.

actix-web-flash-messages Flash messages for actix-web Web applications sometimes need to show a one-time notification to the user - e.g. an error mess

Luca Palmieri 31 Dec 29, 2022
RESTful Todo API with Actix-web and SeaORM. Documented by swagger-ui

RESTful Todo RESTful Todo API with Actix and SeaORM. Documented by swagger-ui Prerequisites Rust Usage Clone the repository and run the following comm

Awiteb 4 Dec 27, 2022
An API project using Rust, Actix Web and JWT. *WIP*

Actix-web REST API with JWT (WIP) A simple CRUD backend app using Actix-web, Diesel and JWT Require Rust Stable Postgres Or using Docker How to run Ma

Akhil Sharma 4 Sep 21, 2023
An implementation of the callbag spec

callbag-rs An implementation of the callbag spec License Licensed under either of Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.o

Teoh Han Hui 29 Dec 5, 2022
A highly customizable, full scale web backend for web-rwkv, built on axum with websocket protocol.

web-rwkv-axum A axum web backend for web-rwkv, built on websocket. Supports BNF-constrained grammar, CFG sampling, etc., all streamed over network. St

Li Junyu 12 Sep 25, 2023
A Google-like web search engine that provides the user with the most relevant websites in accordance to his/her query, using crawled and indexed textual data and PageRank.

Mini Google Course project for the Architecture of Computer Systems course. Overview: Architecture: We are working on multiple components of the web c

Max 11 Aug 10, 2022
A simple authentication flow using Rust and Actix-web, with a PostgreSQL database and a sveltekit frontend.

Rust-auth-example This repository aims to represent a simple authentication flow using Rust and Actix-web, with a PostgreSQL database and a sveltekit

Kival Mahadew 4 Feb 19, 2023
A newsletter with actix-web and sqlx-postgres

Newsletter backend Health check: production Pre-requisites You'll need to install: Rust Docker There are also some OS-specific requirements. Windows c

Nadeem Bhati 4 Dec 10, 2022
Web Application with using Rust(Actix, Diesel and etc)

Santa Service App Used technology stack Web Server with using Rust (Actix, Actix-web, Diesel) Data base (Postgres) Console Application (Tokio) Tasks o

null 3 Jan 8, 2023
Volt - A powerful, fast and memory safe package manager for the web

Volt - A powerful, fast and memory safe package manager for the web

Volt Package Manager 811 Dec 30, 2022
example of a full stack web app (backend and frontend) wrtiten in Rust

rust-fullstack-example An example of creating a full stack web application (backend and frontend) using Rust. Backend Go to ./backend and start the se

mario 41 Dec 16, 2022
Sauron is an html web framework for building web-apps. It is heavily inspired by elm.

sauron Guide Sauron is an web framework for creating fast and interactive client side web application, as well as server-side rendering for back-end w

Jovansonlee Cesar 1.7k Dec 26, 2022
Rust implementation of the `URLPattern` web API

urlpattern This crate implements the URLPattern web API in Rust. We aim to follow the specification as closely as possible. Contributing We appreciate

Deno Land 40 Dec 14, 2022
A pure Rust implementation of the Web Local Storage API, for use in non-browser contexts

Rust Web Local Storage API A Rust implementation of the Web LocalStorage API, for use in non-browser contexts About the Web Local Storage API MDN docs

RICHΛRD ΛNΛYΛ 10 Nov 28, 2022
Ergonomic and modular web framework built with Tokio, Tower, and Hyper

axum axum is a web application framework that focuses on ergonomics and modularity. More information about this crate can be found in the crate docume

Tokio 7.9k Dec 31, 2022
A rust web framework with safety and speed in mind.

darpi A web api framework with speed and safety in mind. One of the big goals is to catch all errors at compile time, if possible. The framework uses

null 32 Apr 11, 2022
Thruster - An fast and intuitive rust web framework

A fast, middleware based, web framework written in Rust

null 913 Dec 27, 2022
A full-featured and easy-to-use web framework with the Rust programming language.

Poem Framework A program is like a poem, you cannot write a poem without writing it. --- Dijkstra A full-featured and easy-to-use web framework with t

Poem Web 2.2k Jan 6, 2023
Seed is a Rust front-end framework for creating fast and reliable web apps with an Elm-like architecture.

Seed is a Rust front-end framework for creating fast and reliable web apps with an Elm-like architecture.

null 3.6k Jan 6, 2023