-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple server with database #17
Conversation
I forgot to mention that the server was built on ClearLinux. I don't guarantee that these steps would work nor on other OSs, neither on other distributions. |
@dikuchan I gave it a chance, but the "hello" wasn't delivered to me.
Also minor things:
My suggestions are:
Please discuss. |
use diesel::RunQueryDsl; | ||
use actix_web::{web, HttpResponse}; | ||
|
||
fn get_users(pool: web::Data<Pool>) -> Result<Vec<User>, diesel::result::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is DAL method, it shouldn't be in API
web, App, HttpServer, | ||
middleware::Logger, | ||
}; | ||
use env_logger::Env; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean we already have loggin? If so, it should be documented somewhere.
.route("/hello", web::get().to(api::auth::hello)) | ||
.wrap(Logger::default()) | ||
}) | ||
.bind("localhost:8080")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be in config or not?
Ok(items) | ||
} | ||
|
||
pub async fn hello(db: web::Data<Pool>) -> Result<HttpResponse, actix_web::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also like it to be in another package, not in auth. But it's up to you.
Using Actix as web framework and Diesel as ORM for Postgres.
In the current state, building procces is complicated and not automated. To successfuly build the server, reproduce next steps (would be useful for @FortyWays):
rustup
(using official site, distro package, Docker or whatever).postgresql-devel
(name depends on your distro) package in order for Diesel to link during linkage.DATABASE_URL
. For example,Where username and password are the same as in the previous step, IP could be retrieved from Docker and name of the database is custom. Or, as an alternative, variable can be specified in
.env
file in thebackend
directory.6. Run
cargo run
in thebackend
directory. It should successfuly compile and print that it started n workers and a service on localhost. For example,localhost:8080/hello
has status 200.Additionaly, you can fill the database with sample data. View table structure with DataGrid, for example, then add a new field. JSON response should return all fields in the table.