Sketching out web mvc part of std lib.
This commit is contained in:
parent
5351a7b6a4
commit
bb2edc1d49
51
dm_lib/std/web/mvc/controller.dm
Normal file
51
dm_lib/std/web/mvc/controller.dm
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user