Sketching out web mvc part of std lib.

This commit is contained in:
Jesse Brault 2024-12-04 19:25:23 -06:00
parent 5351a7b6a4
commit bb2edc1d49

View File

@ -0,0 +1,51 @@
ns std::web::mvc
use std::web::{HttpRequest, HttpResponse}
pub int Controller {
fn handle(req: HttpRequest, res: HttpResponse)
}
pub ann Path {
path: String
}
pub ann Get {
path: Option<String>
}
pub ann Post {
path: Option<String>
}
#decorator
pub impl RestController(fld target: Any) : Controller {
impl fn handle(req, res) {
// Use reflection
}
}
// Usage
+RestController
@Path("/greeting")
pub impl GreetingController {
fld greeting: mut String
@Get
pub fn getGreeting() = "Hello, World!"
@Post
pub fn setGreeting(@RequestBody newGreeting: String) {
self.greeting = newGreeting
return self.greeting
}
}
fn main() {
let server =
server << GreetingController()
server.listen 8080
}