extern crate stonehenge; use stonehenge::components::{Component, Page, TextVariant}; use stonehenge::{App, HttpMethod, HttpStatus, Request, Response, Route, Router}; fn homepage(_: Request) -> Response { // These are components. They can nest within eachother using vectors, and can (soon) receive WASM // functions corresponding to most DOM events (eg onClick, onHover, etc) let mut greeting = Component::text(TextVariant::H1, String::from("Hello world")); greeting.add_style("color", "#00AAFF"); let mut content = Component::container(vec![ greeting, Component::text(TextVariant::Body1, String::from("This is Stonehenge")), Component::text( TextVariant::Body1, String::from("It's a full-stack rust web framework I've been working on"), ), ]); content.add_style("background-color", "orange"); content.add_style("color", "blue"); // There's a separate page object because the top level component needs to handle CSS compilation, // headers, routing, and app state. let page = Page::new(content); Response::html(HttpStatus::OK, page) } fn about(_: Request) -> Response { // TODO: JSON still sucks... gotta find a better API for this let body = String::from("{\"page\": \"about\"}"); Response::json(HttpStatus::OK, body) } fn main() { // Routing API needs work let router = Router { path: "/", routes: vec![ Route { path: "/", handler: homepage, method: HttpMethod::GET, }, Route { path: "/about", handler: about, method: HttpMethod::GET, }, ], nested_routers: vec![], }; // Eventually, the app will also have config, an ORM, and installed module support let app = App::new(router); app.start(); }