INitial backend setup
This commit is contained in:
parent
5c88095889
commit
e74990b2ac
3 changed files with 2220 additions and 2 deletions
2188
polsevev_dev_backend/Cargo.lock
generated
2188
polsevev_dev_backend/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,3 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
poem = "1.2"
|
||||||
|
poem-openapi = { version = "1.2", features = ["swagger-ui"] }
|
||||||
|
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
sqlx = { version = "0.6.0", features = ["runtime-tokio-rustls", "sqlite"] }
|
||||||
|
|
|
@ -1,3 +1,29 @@
|
||||||
fn main() {
|
use poem::{listener::TcpListener, Route};
|
||||||
println!("Hello, world!");
|
use poem_openapi::{param::Query, payload::PlainText, OpenApi, OpenApiService};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
|
struct Api;
|
||||||
|
|
||||||
|
#[OpenApi]
|
||||||
|
impl Api {
|
||||||
|
#[oai(path = "/hello", method = "get")]
|
||||||
|
async fn index(&self, name: Query<Option<String>>) -> PlainText<String> {
|
||||||
|
match name.0 {
|
||||||
|
Some(name) => PlainText(format!("hello, {}!", name)),
|
||||||
|
None => PlainText("hello!".to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), std::io::Error> {
|
||||||
|
let api_service =
|
||||||
|
OpenApiService::new(Api, "Hello World", "1.0").server("http://localhost:3000/api");
|
||||||
|
let ui = api_service.swagger_ui();
|
||||||
|
let app = Route::new().nest("/api", api_service).nest("/", ui);
|
||||||
|
|
||||||
|
let pool = SqlitePool::connect("db.db");
|
||||||
|
poem::Server::new(TcpListener::bind("127.0.0.1:3000"))
|
||||||
|
.run(app)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue