Code Monkey home page Code Monkey logo

actix-todo's Introduction

actix-todo Build Status

Simple TODO list API made in rust

Requirements

  • Rust
  • Docker
  • docker-compose

Usage

# Copy example .env file
cp .env.example .env

# Run postgres
docker-compose up -d postgres

# Install diesel
cargo install diesel_cli --no-default-features --features postgres

# Run db migrations
DATABASE_URL=postgres://actix:actix@localhost:5432/actix diesel migration run

# Run unit tests
cargo test

# Run integration tests
cargo test --features "integration"

# Run the server (Add --release for an optimized build)
cargo run 
curl -s http://localhost:8080/

Routes

  • GET / -> Status

    Response:

    {
      "status": "Up"
    }
    
  • GET /todos -> Get todo lists

    Response:

    [
      {
        "id": 1,
        "title": "Grocery list"
      },
      ...
    [
    
  • GET /todos/1 -> Get single todo list

    Response:

    {
      "id": 1,
      "title": "Grocery list"
    }
    
  • POST /todos -> Create todo list

    Request Header:

    Content-Type: application/json
    

    Request Body:

    {
      "title": "List title"    
    }
    

    Response:

    {
      "id": 1,
      "title": "Grocery list"
    }
    
  • GET /todos/1/items -> Get items of the todo list

    Response:

    [
      {
        "id": 1,
        "list_id": 1,
        "title": "Milk",
        "checked": true
      },
      {
        "id": 1,
        "list_id": 2,
        "title": "Bread",
        "checked": false
      }
    ]
    
  • GET /todos/1/items/1 -> Get single item of the todo list

    Response:

    {
      "id": 1,
      "list_id": 1,
      "title": "Milk",
      "checked": true
    }
    
  • POST /todos/1/items -> Create todo list item

    Request Header:

    Content-Type: application/json
    

    Request Body:

    {
      "title": "Eggs"    
    }
    

    Response:

    {
      "id": 1,
      "list_id": 1,
      "title": "Eggs",
      "checked": false
    }
    
  • PUT /todos/1/items/1 -> Check todo

    Response:

    {
      "result": true
    }
    

    Result:

    • true -> Checked
    • false -> Already checked. Nothing to do.

actix-todo's People

Contributors

nemesiscodex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

actix-todo's Issues

Good demo, thank you! Can you add in JWT? Thanks.

Hi Nemesiscodex,

Thanks for your great demo!
Your video show the good practice of how to use RUST/Actix for web back end.

Do you have time to add in JWT? Thanks.
It would be better if you add front end (seed? or yew?) to make a full demo.

Regards
Scott Huang

Errors on config.rs lastest config version: 0.12

config.rs

pub use config::ConfigError;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct ServerConfig {
  pub host: String,
  pub port: i32,
}

#[derive(Deserialize)]
pub struct Config {
  pub server: ServerConfig
}

impl Config {
  pub fn from_env() -> Result<Self, ConfigError> {
    let mut cfg = config::Config::new();
    cfg.merge(config::Environment::new())?;
    cfg.try_into()
  }
}

Cargo.toml

[dependencies]
actix-web = "^4"
actix-rt = "^2"
serde = { version = "^1", features = ["derive"] }
dotenv = "^0.15"
config = "^0.12"
$ cargo check
    Checking todo-actix v0.1.0 (/home/notecomm/prust/todo-actix)
error[E0624]: associated function `new` is private
  --> src/config.rs:22:35
   |
22 |     let mut cfg = config::Config::new();
   |                                   ^^^ private associated function
   |
  ::: /home/notecomm/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.12.0/src/config.rs:39:5
   |
39 |     pub(crate) fn new(value: Value) -> Self {
   |     --------------------------------------- private associated function defined here

error[E0061]: this function takes 1 argument but 0 arguments were supplied
  --> src/config.rs:22:19
   |
22 |     let mut cfg = config::Config::new();
   |                   ^^^^^^^^^^^^^^^^^^^-- supplied 0 arguments
   |                   |
   |                   expected 1 argument
   |
note: associated function defined here
  --> /home/notecomm/.cargo/registry/src/github.com-1ecc6299db9ec823/config-0.12.0/src/config.rs:39:19
   |
39 |     pub(crate) fn new(value: Value) -> Self {
   |                   ^^^

warning: use of deprecated associated function `config::Config::merge`: please use 'ConfigBuilder' instead
  --> src/config.rs:23:9
   |
23 |     cfg.merge(config::Environment::new())?;
   |         ^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated associated function `config::Environment::new`: please use 'Environment::default' instead
  --> src/config.rs:23:36
   |
23 |     cfg.merge(config::Environment::new())?;
   |                                    ^^^

error[E0271]: type mismatch resolving `<config::Config as TryFrom<config::Config>>::Error == ConfigError`
  --> src/config.rs:24:9
   |
24 |     cfg.try_into()
   |         ^^^^^^^^ expected enum `Infallible`, found enum `ConfigError`

error[E0277]: the trait bound `config::Config: std::convert::From<config::Config>` is not satisfied
  --> src/config.rs:24:9
   |
24 |     cfg.try_into()
   |         ^^^^^^^^ the trait `std::convert::From<config::Config>` is not implemented for `config::Config`
   |
   = note: required because of the requirements on the impl of `Into<config::Config>` for `config::Config`
   = note: required because of the requirements on the impl of `TryFrom<config::Config>` for `config::Config`
   = note: required because of the requirements on the impl of `TryInto<config::Config>` for `config::Config`

Some errors have detailed explanations: E0061, E0271, E0277, E0624.
For more information about an error, try `rustc --explain E0061`.
warning: `todo-actix` (bin "todo-actix") generated 2 warnings
error: could not compile `todo-actix` due to 4 previous errors; 2 warnings emitted

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.