Alexey Velikiy
3 years ago
6 changed files with 1203 additions and 0 deletions
@ -0,0 +1,45 @@
|
||||
{ |
||||
// Use IntelliSense to learn about possible attributes. |
||||
// Hover to view descriptions of existing attributes. |
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
||||
"version": "0.2.0", |
||||
"configurations": [ |
||||
{ |
||||
"type": "lldb", |
||||
"request": "launch", |
||||
"name": "Debug executable 'hastic'", |
||||
"cargo": { |
||||
"args": [ |
||||
"build", |
||||
"--bin=hastic", |
||||
"--package=hastic" |
||||
], |
||||
"filter": { |
||||
"name": "hastic", |
||||
"kind": "bin" |
||||
} |
||||
}, |
||||
"args": [], |
||||
"cwd": "${workspaceFolder}" |
||||
}, |
||||
{ |
||||
"type": "lldb", |
||||
"request": "launch", |
||||
"name": "Debug unit tests in executable 'hastic'", |
||||
"cargo": { |
||||
"args": [ |
||||
"test", |
||||
"--no-run", |
||||
"--bin=hastic", |
||||
"--package=hastic" |
||||
], |
||||
"filter": { |
||||
"name": "hastic", |
||||
"kind": "bin" |
||||
} |
||||
}, |
||||
"args": [], |
||||
"cwd": "${workspaceFolder}" |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,12 @@
|
||||
[package] |
||||
name = "hastic" |
||||
version = "0.0.1" |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
tokio = { version = "1", features = ["full"] } |
||||
warp = "0.3" |
||||
parking_lot = "0.11.2" |
||||
serde = { version = "1.0", features = ["derive"] } |
@ -0,0 +1,33 @@
|
||||
use warp::{Filter, http::Response }; |
||||
use warp::filters::method::post; |
||||
|
||||
|
||||
mod user_service; |
||||
|
||||
fn json_body() -> impl Filter<Extract = (user_service::User,), Error = warp::Rejection> + Clone { |
||||
// When accepting a body, we want a JSON body
|
||||
// (and to reject huge payloads)...
|
||||
warp::body::content_length_limit(1024 * 16).and(warp::body::json()) |
||||
} |
||||
|
||||
#[tokio::main] |
||||
async fn main() { |
||||
let routes = warp::any().map(|| {
|
||||
Response::builder() |
||||
.header("Access-Control-Allow-Origin", "*") |
||||
.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE") |
||||
.header("Access-Control-Allow-Headers", "*") |
||||
.body("and a custom body") |
||||
// "Hello, World!"
|
||||
}); |
||||
let hello = warp::path!("api" / "auth" / "signin") |
||||
.and(post()) |
||||
.and(json_body()) |
||||
.map(|user: user_service::User| { |
||||
format!("Hello, {}!", &user.username) |
||||
}); |
||||
|
||||
warp::serve(routes) |
||||
.run(([127, 0, 0, 1], 8000)) |
||||
.await; |
||||
} |
@ -0,0 +1,18 @@
|
||||
use serde::{ Deserialize, Serialize }; |
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)] |
||||
pub struct User { |
||||
pub username: String, |
||||
pub password: String |
||||
} |
||||
|
||||
pub struct UserService { |
||||
|
||||
} |
||||
|
||||
impl UserService { |
||||
pub fn new() -> UserService { |
||||
UserService{} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue