diff --git a/.gitignore b/.gitignore index 810fe25..8707c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ target/ -server + *.wasm herovm_build/ diff --git a/herodb/src/server/instructions.md b/herodb/src/server/instructions.md new file mode 100644 index 0000000..98d610b --- /dev/null +++ b/herodb/src/server/instructions.md @@ -0,0 +1,92 @@ +You're a Rust developer assistant. + +Please generate a complete Rust web server using `poem` and `poem-openapi`. It should: + +1. Create a basic `#[OpenApi]` interface. +2. Automatically generate and serve an OpenAPI 3.0 spec at `/api/openapi.json`. +3. Serve a Swagger UI interface at `/docs`. +4. Expose a function I define in another module (e.g., `my_logic::do_something()`). +5. The endpoint should be `/do` (HTTP GET) and return a JSON response. + +Use these crates: +- `poem` +- `poem-openapi` +- `tokio` +- `uuid` (optional, if needed) + +We want to create crud and also other methods of herodb/src/zaz/models + +To see how we call this model logic see herodb/src/zaz/cmd/examples.rs + +And use it inside the API handler. + +The project should have: +- `main.rs` (entry point) +- `sale.rs` (logic per file e.g. sale, product, ...) +- Clear type annotations and minimal boilerplate. +``` + +--- + +## ๐Ÿงช Example Output from AI Based on That Prompt + +### `Cargo.toml` + +```toml +[package] +name = "poem-api-server" +version = "0.1.0" +edition = "2021" + +[dependencies] +poem = "1" +poem-openapi = "3" +tokio = { version = "1", features = ["full"] } +``` + + +### `src/main.rs` + +```rust +use poem::{listener::TcpListener, Route, Server}; +use poem_openapi::{payload::Json, OpenApi, OpenApiService}; + +mod my_logic; + +struct Api; + +#[OpenApi] +impl Api { + #[oai(path = "/do", method = "get")] + async fn do_action(&self) -> Json { + Json(my_logic::do_something()) + } +} + +#[tokio::main] +async fn main() { + let api_service = + OpenApiService::new(Api, "My API", "1.0").server("http://localhost:3000/api"); + + let ui = api_service.swagger_ui(); + + let app = Route::new() + .nest("/api", api_service) + .nest("/docs", ui); + + Server::new(TcpListener::bind("127.0.0.1:3000")) + .run(app) + .await + .unwrap(); +} +``` + +--- + +### โœ… Result + +- Open `/api/do` โ†’ Calls your logic and returns a JSON response. +- Open `/docs` โ†’ Interactive Swagger UI +- Open `/api/openapi.json` โ†’ Full OpenAPI spec + +---