| 12345678910111213141516171819202122232425262728293031 |
- using Astralis;
- using Invercargill;
- using Invercargill.DataStructures;
- // Simple handler for /hello endpoint
- class HelloHandler : Object, RouteHandler {
- public async HttpResult handle_route(HttpContext http_context, RouteContext route_context) throws Error {
- print("Handling /hello\n");
- return new BufferedHttpResult.from_string("Hello from Astralis!");
- }
- }
- // Simple handler for /json endpoint
- class JsonHandler : Object, RouteHandler {
- public async HttpResult handle_route(HttpContext http_context, RouteContext route_context) throws Error {
- print("Handling /json\n");
- var headers = new Catalogue<string, string>();
- headers.add("Content-Type", "application/json");
- return new BufferedHttpResult.from_string("{ \"message\": \"Hello JSON\" }", StatusCode.OK, headers);
- }
- }
- void main() {
- var router = new Router();
- var server = new Server(8080, router);
-
- router.map("/hello", new HelloHandler());
- router.map("/json", new JsonHandler());
- server.run();
- }
|