-use tokio::join;
-
-async fn guten_tag() {
- println!("Guten Tag!");
-}
+use tokio::io::AsyncWriteExt;
+use tokio::net::{TcpListener, TcpStream};
#[tokio::main]
async fn main() {
- let task1 = tokio::spawn(async {
- println!("Hello, world!");
- });
- let task2 = tokio::spawn(guten_tag());
+ let listener = TcpListener::bind("127.0.0.1:8181").await.unwrap();
+
+ loop {
+ let (stream, _) = listener.accept().await.unwrap();
+ handle_connection(stream).await;
+ }
+}
+
+async fn handle_connection(mut stream: TcpStream) {
+ let contents = "{\"balance\": 0.00}";
- let (r1, r2) = join!(task1, task2);
- r1.unwrap();
- r2.unwrap()
+ let response = format!(
+ "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\n\r\n{}",
+ contents.len(),
+ contents
+ );
+ assert!(stream.write(response.as_bytes()).await.unwrap() > 0);
+ stream.flush().await.unwrap();
}