Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanarus/aoi
https://github.com/kanarus/aoi
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kanarus/aoi
- Owner: kanarus
- License: mit
- Created: 2023-01-16T13:51:29.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-30T06:57:05.000Z (almost 2 years ago)
- Last Synced: 2024-10-19T14:01:25.827Z (27 days ago)
- Language: Rust
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
aoi - Pre Development Draft
aoi *- [葵] name of popular plant in Japan -* will be **struct based web framework**.\
This is pre development draft.
## Features ( under plannning )
- **struct based architecture** where a server is a struct
- actively using **macros**
## Examples ( under planning; DOESN'T WORK )
### simple server
```rust
#[server]
MyServer {
#[GET /]
{
self.OK("Hello!")
}
}#[main]
{
let my_server = MyServer;
bloom!(":3000", my_server)
}
```
```sh
$ curl http://localhost:3000
Hello!
```### handle db, path params, request body
```rust
struct User {
id: u64,
name: String,
}struct CreateUser {
name: String,
password: String,
}#[server]
UserServer {
conn: ConnectionPool,
} {
#[GET /api/users/{id:u64}]
{
let user = SQL![
SELECT id, name FROM users
WHERE id = $id
; as User]
.fetch_one(&self.conn)
.await?;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)
}
}#[main]
{
let connection_pool = PgPoolOptions::new()
.max_connections(5)
.connect(
"postgres://postgres:password@localhost/test"
).await?;let user_server = UserServer {
conn: connection_pool,
};bloom!(":8080", user_server)
}
```### nest servers
```rust
struct CreateUser {
name: String,
password: String,
}#[server]
RootServer {
#[GET /]
{
self.OK("Hello!")
}#[GET /health_check]
{
self.NoContent()
}
}#[server]
UserServer {
conn: ConnectionPool,
} {
#[GET /{id:u64}]
{
let user = SQL![
SELECT id, name FROM users
WHERE id = $id
; as User]
.fetch_one(&self.conn)
.await?;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)
}
}#[main]
{
let connection_pool = PgPoolOptions::new()
.max_connections(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
)
}
```