fairingrey / actix-realworld-example-app Goto Github PK
View Code? Open in Web Editor NEW[UNMAINTAINED] Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.
[UNMAINTAINED] Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.
when i do cargo build this error comes up. What is it ?
ubuntu@ubuntu:~/rust/projektx$ cargo build Compiling conduit v0.1.0 (/home/ubuntu/rust/projektx) error[E0277]: the trait bound
uuid::Uuid: diesel::Expressionis not satisfied --> src/models/article.rs:18:17 | 18 | #[derive(Debug, Insertable)] | ^^^^^^^^^^ the trait
diesel::Expressionis not implemented for
uuid::Uuid| = note: required because of the requirements on the impl of
diesel::expression::AsExpressiondiesel::sql_types::Uuidfor
uuid::Uuid`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article.rs:18:17
|
18 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article.rs:38:17
|
38 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article.rs:38:17
|
38 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article_tag.rs:15:17
|
15 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article_tag.rs:15:17
|
15 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/comment.rs:16:17
|
16 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/comment.rs:16:17
|
16 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/follower.rs:15:17
|
15 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/follower.rs:15:17
|
15 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article.rs:18:17
|
18 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &'insert uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &'insert uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article.rs:38:17
|
38 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &'insert uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &'insert uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/article_tag.rs:15:17
|
15 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &'insert uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &'insert uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/comment.rs:16:17
|
16 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &'insert uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &'insert uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound uuid::Uuid: diesel::Expression
is not satisfied
--> src/models/follower.rs:15:17
|
15 | #[derive(Debug, Insertable)]
| ^^^^^^^^^^ the trait diesel::Expression
is not implemented for uuid::Uuid
|
= note: required because of the requirements on the impl of diesel::Expression
for &'insert uuid::Uuid
= note: required because of the requirements on the impl of diesel::expression::AsExpression<diesel::sql_types::Uuid>
for &'insert uuid::Uuid
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 15 previous errors
For more information about this error, try rustc --explain E0277
.
error: could not compile conduit
.
To learn more, run the command again with --verbose.
ubuntu@ubuntu:~/rust/projektx$
`
This actually doesn't seem too difficult. Consider implementing the FromRequest
trait for our auth method so we don't have to call a specific method all the time to get the auth object.
https://actix.rs/actix-web/actix_web/trait.FromRequest.html
Concerning code is here:
https://github.com/fairingrey/actix-realworld-example-app/blob/master/src/utils/auth.rs
Thanks to @colelawrence for letting me know of the idea!
App::new() .register_data(Data::new(state)) .wrap(Logger::default()) .wrap(cors) .wrap(crate::middleware::authen_middleware::Authentication) .configure(routes) }) .bind(&bind_address) .unwrap_or_else(|_| panic!("Could not bind server to address {}", &bind_address)) .start();
AFAIK there isn't any idiomatic way I know of to do unit testing in an actix-web application, as that would involve having to mock client messages on valid data, and given handlers are async ('technically' speaking, as the db actor is still sync) this might prove to be a bit difficult...
If anyone has suggestions or ways to approach this issue, feel free to make a comment or open a PR. Otherwise I'll try looking around and see what other people are doing before I attempt to make a test suite myself.
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?
Whatever in code that says unimplemented!()
still has yet to be implemented, though it's pretty much all message handling logic for DbExecutor.
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 ๐
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.
I think would be better to handle authentication as middleware of a base route, I think wrap
can do the job in actix.
Feel free to criticize this idea considering that I'm not an actix expert! ๐
Related: #19
IMHO, one of the major deficiencies of actix-web documentation and codebase is that examples may not be self-contained, being clean enough and straighforward enough for newcomers into the library. By "self contained" I mean: "copy from the browser, paste into two files: Cargo.toml and main.rs ... fire cargo and it works."
Writing an end-to-end, real world application, containing reasonable unit tests and integration tests would potentially eradicate this deficiency.
Also, since Actix 2.0 now employs async/await, several examples from the documentation website are just outdated and so, if you are a newbie and copy/paste the example... it will take you a number of hours until you realise that you were simply misguided.
In my case in particular, I've struggled a lot to write a proof of concept which looks like code in production. Examples in the documentation are incomplete (they are just snippets of code), not exercising real world scenarios, which render them sometimes almost useless... apart from the syntax they introduce or some mechanics they illustrate.
I had difficulties finding an example which "just works", which does something so mundane: a simple client code (using actix-web client, not anything else!) which sends a post request containing some JSON and receives some other JSON as response. There's no such example containing unit tests and integration tests (which just work!) as far as I know and, in order to build one, I had to invest a lot of time and effort digging into the code base of a number of repositories.
Then, finally the coin dropped after a number of hours: it does not work because I'm using Actix 2.0 but trying documentation from the website which assumes Actix 1.0.
So, once again: Writing proper unit tests and integration tests in a context of a real world application is a must. Ideally, employing Actix 2.0 as #19 suggests.
Just downloaded/set it up to try it out.
Any idea what's causing this?
thread 'arbiter:ed63170e-3426-4aaa-bbb5-2ccfbfb2147a:actix-net-worker-3' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:4c9e2b97-7110-42c1-8fe1-abb61979e105:actix-net-worker-4' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:c3b18044-efe3-49da-8978-3af67764e026:actix-net-worker-11' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:d4df4aae-37c6-4a75-af6e-c3426a11fb78:actix-net-worker-8' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:7f6bb722-363b-40cd-8788-bc02f2806eee:actix-net-worker-9' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:aa2b968a-40f0-4d85-8ace-7653ba749b29:actix-net-worker-7' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:96bb52d2-f4f1-46bb-857c-2a5ee7949153:actix-net-worker-2' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
thread 'arbiter:882e27d2-d090-4ab0-9b78-e5f76497d71f:actix-net-worker-10' panicked at 'Failed to create pool.: InternalServerError', src/libcore/result.rs:997:5
diesel database setup
Hi, I'm trying to figure this out, since apparently diesel doesn't support async (nor underlying postgres driver).
You're not explicitly specifying number of workers for HttpServer
, which means it will create (number of cpu cores)-threads for handling incoming http requests.
Now, when next http request runs heavy database query through diesel it will block current thread. And for example, if my system has 4 cpu cores, it's enough to run 4 heavy http requests simultaneously to completely DoS entire server.
Is that correct?
Looking at all the RealWorld examples, I did not find much in the way of talking about how to use it, I understand it is a larger picture app, meant to look the same in any language, but a few notes would help some new to RealWorld to get started.
This is on the front end
https://thinkster.io/tutorials/fullstack/building-the-frontend
The API:
https://github.com/gothinkster/realworld/tree/master/api
With no documents, I have no idea what to expect from the back end, but I am interested.
Looking at the code the project looks great.
Thanks @fairingrey.
when i run cargo run
it appears an error
"thread 'main' panicked at 'Failed to create pool.: InternalServerError', src/app/mod.rs:31:25"
what is it? how to fix it? I'm a beginner to using Rust.
thanks.
https://github.com/fairingrey/actix-realworld-example-app/blob/master/.travis.yml is actually pretty scarce at the moment. All it does is run cargo check --verbose
on the codebase to see if there are any syntax errors.
The idea later is that we should perform some sort of database dump (probably pg_dump
to .sql
), see that Travis imports the db into their box, run the backend application on their machine, run tests against it, and then gracefully shutdown after all tests have hopefully passed.
Hi,
@fairingrey apart from tests, could you briefly expose what is this project missing to be published as a complete realworld-example-app?
Thank you.
With the release of actix-web 1.0 (a major point release!), this repo should be migrated to use the updated dependency.
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).
Hello guys and thank you so much for the real world app example. I will use it ๐
I was just thinking , do you think it could be possible to update it to the latest actix-web and maybe try with the proc_macro way of doing ?
I tried it on my own app but I am not sure about the proc/cons for traditional way to write handlers vs proc_macro way.
What do you think ? Should we try to make a real world example this way as well to see the pros and cons ?
Best regards,
Arn
Any planning for actix 2.0? I think as async await is released its a good time to update it and see how ergonomic actix is for realworld example app.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.