Code Monkey home page Code Monkey logo

rocket-diesel-rest-api-example's Introduction

Rocket, Diesel, MySQL, Rest API Tutorial

Build Restful CRUD API for a managing heroes within our Database using Rocket and Diesel.

Requirements

  1. Rust and Cargo - 1.26.0 (nightly)

  2. Diesel CLI - 1.1.0

  3. Mysql - 5.x.x

Steps to Setup

1. Clone the application

git clone https://github.com/sean3z/rocket-diesel-rest-api-example.git

2. Create DATABASE_URL environment variable

export DATABASE_URL=mysql://user:pass@localhost/heroes

3. Run Database migration

diesel migration run

4. Build and run the app using cargo

cargo build --release && cd target/release/
sudo ROCKET_ENV=prod ./hero-api

The app will start running at http://localhost:80.

Alternatively, you can run the app in development mode -

cargo run

Explore Rest APIs

The app defines following CRUD APIs.

GET /heroes

POST /hero

PUT /hero/{heroId}

DELETE /hero/{heroId}

You can test them using postman or any other rest client.

Learn more

You can find the tutorial for this application on my blog -

https://medium.com/p/1867308352d8/

rocket-diesel-rest-api-example's People

Contributors

aalonzolu avatar pickfire avatar sean3z avatar zargold 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

rocket-diesel-rest-api-example's Issues

Compile fails on latest rust 1.28

With stable rust one of dependencies named pear won't compile as it needs nightly version.
With nightly rust (1.28) one of dependencies named diesel won't compile as it needs stable version!

   Compiling diesel v1.3.0
error[E0277]: the trait bound `<expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Add` is not satisfied
  --> /home/aario/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-1.3.0/src/expression/count.rs:58:39
   |
58 | #[derive(Debug, Clone, Copy, QueryId, DieselNumericOps)]
   |                                       ^^^^^^^^^^^^^^^^ the trait `sql_types::ops::Add` is not implemented for `<expression::count::CountStar as expression::Expression>::SqlType`
   |
   = help: consider adding a `where <expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Add` bound
   = help: see issue #48214
   = help: add #![feature(trivial_bounds)] to the crate attributes to enable

error[E0277]: the trait bound `<expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Sub` is not satisfied
  --> /home/aario/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-1.3.0/src/expression/count.rs:58:39
   |
58 | #[derive(Debug, Clone, Copy, QueryId, DieselNumericOps)]
   |                                       ^^^^^^^^^^^^^^^^ the trait `sql_types::ops::Sub` is not implemented for `<expression::count::CountStar as expression::Expression>::SqlType`
   |
   = help: consider adding a `where <expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Sub` bound
   = help: see issue #48214
   = help: add #![feature(trivial_bounds)] to the crate attributes to enable

error[E0277]: the trait bound `<expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Mul` is not satisfied
  --> /home/aario/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-1.3.0/src/expression/count.rs:58:39
   |
58 | #[derive(Debug, Clone, Copy, QueryId, DieselNumericOps)]
   |                                       ^^^^^^^^^^^^^^^^ the trait `sql_types::ops::Mul` is not implemented for `<expression::count::CountStar as expression::Expression>::SqlType`
   |
   = help: consider adding a `where <expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Mul` bound
   = help: see issue #48214
   = help: add #![feature(trivial_bounds)] to the crate attributes to enable

error[E0277]: the trait bound `<expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Div` is not satisfied
  --> /home/aario/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-1.3.0/src/expression/count.rs:58:39
   |
58 | #[derive(Debug, Clone, Copy, QueryId, DieselNumericOps)]
   |                                       ^^^^^^^^^^^^^^^^ the trait `sql_types::ops::Div` is not implemented for `<expression::count::CountStar as expression::Expression>::SqlType`
   |
   = help: consider adding a `where <expression::count::CountStar as expression::Expression>::SqlType: sql_types::ops::Div` bound
   = help: see issue #48214
   = help: add #![feature(trivial_bounds)] to the crate attributes to enable

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `diesel`.

Already reported it to diesel, but they expect a bug report to be around stable rust (As in their checkboxes in their issue template):
diesel-rs/diesel#1730

Compile error

when I want to run this project i got this error :

rocket-diesel-rest-api-example git:(master) cargo build --release && cd target/release/
   Compiling pear_codegen v0.0.14
   Compiling hyper v0.10.13
   Compiling serde_derive_internals v0.23.0
   Compiling diesel v1.1.1
   Compiling rayon v0.7.1
error[E0432]: unresolved import `syntax::ast::SpannedIdent`
  --> /home/mehrdad/.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.14/src/lib.rs:27:56
   |
27 | use syntax::ast::{ItemKind, MetaItem, FnDecl, PatKind, SpannedIdent};
   |                                                        ^^^^^^^^^^^^ no `SpannedIdent` in `ast`

error[E0609]: no field `identifier` on type `syntax::ast::PathSegment`
   --> /home/mehrdad/.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.14/src/lib.rs:131:59
    |
131 |             let penultimate = path.segments[num_segs - 2].identifier.name.as_str();
    |                                                           ^^^^^^^^^^ unknown field
    |
    = note: available fields are: `ident`, `parameters`

error[E0609]: no field `identifier` on type `syntax::ast::PathSegment`
   --> /home/mehrdad/.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.14/src/lib.rs:138:48
    |
138 |         let last = path.segments[num_segs - 1].identifier.name.as_str();
    |                                                ^^^^^^^^^^ unknown field
    |
    = note: available fields are: `ident`, `parameters`

error[E0609]: no field `identifier` on type `syntax::ast::PathSegment`
   --> /home/mehrdad/.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.14/src/lib.rs:147:40
    |
147 |     let first_ident = path.segments[0].identifier.name.as_str();
    |                                        ^^^^^^^^^^ unknown field
    |
    = note: available fields are: `ident`, `parameters`

error[E0599]: no variant named `TupField` found for type `syntax::ast::ExprKind` in the current scope
   --> /home/mehrdad/.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.14/src/lib.rs:340:9
    |
340 |         ExprKind::TupField(indexed_expr, i) => {
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variant not found in `syntax::ast::ExprKind`

error[E0599]: no variant named `TupField` found for type `syntax::ast::ExprKind` in the current scope
   --> /home/mehrdad/.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.14/src/lib.rs:341:51
    |
341 |             let remake = |new_expr: Vec<P<Expr>>| ExprKind::TupField(new_expr[0].clone(), i);
    |                                                   ^^^^^^^^^^^^^^^^^^ variant not found in `syntax::ast::ExprKind`

error: aborting due to 6 previous errors

Some errors occurred: E0432, E0599, E0609.
For more information about an error, try `rustc --explain E0432`.
error: Could not compile `pear_codegen`.
warning: build failed, waiting for other jobs to finish...
error: build failed

may please help me to fix it ?!

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.