aoi - [葵] name of popular plant in Japan - is struct based web framework.\ This is pre development draft.
```rust
MyServer { #[GET /] { self.OK("Hello!") } }
{
let myserver = MyServer;
bloom!(":3000", myserver)
}
sh
$ curl http://localhost:3000
Hello!
```
```rust struct User { id: u64, name: String, }
struct CreateUser { name: String, password: String, }
UserServer {
conn: ConnectionPool
self.OK(user)
}
#[POST /api/users, body: CreateUser]
{
let CreateUser { name, password } = body;
let created_user = SQL![
INSERT INTO users (name, password) VALUES ($name, $password)
RETURNING id, name
; as User]
.fetch_one(&self.conn)
.await?;
self.Created(created_user)
}
}
{ let connectionpool = PgPoolOptions::new() .maxconnections(5) .connect( "postgres://postgres:password@localhost/test" ).await?;
let user_server = UserServer {
conn: connection_pool,
};
bloom!(":8080", user_server)
} ```
```rust struct CreateUser { name: String, password: String, }
RootServer { #[GET /] { self.OK("Hello!") }
#[GET /health_check]
{
self.NoContent()
}
}
UserServer {
conn: ConnectionPool
self.OK(user)
}
#[POST /, body: CreateUser]
{
let CreateUser { name, password } = body;
let created_user = SQL![
INSERT INTO users (name, password) VALUES ($name, $password)
RETURNING id, name
; as User]
.fetch_one(&self.conn)
.await?;
self.Created(created_user)
}
}
{ let connectionpool = PgPoolOptions::new() .maxconnections(5) .connect( "postgres://postgres:password@localhost/test" ).await?;
let user_server = UserServer {
conn: connection_pool,
};
let root_server = RootServer;
bloom!(":8080",
/api/users => user_server,
/ => root_server
)
} ```