| 12345678910111213141516171819202122232425262728 |
- using Astralis;
- using Invercargill;
- using Invercargill.DataStructures;
- // Simple handler for /hello endpoint
- class HelloEndpoint : Object, Endpoint {
- public async HttpResult handle_request(HttpContext http_context, RouteContext route) throws Error {
- print("Handling /hello\n");
- return new HttpStringResult("Hello from Astralis!");
- }
- }
- // Simple handler for /json endpoint
- class JsonEndpoint : Object, Endpoint {
- public async HttpResult handle_request(HttpContext http_context, RouteContext route) throws Error {
- print("Handling /json\n");
- return new HttpStringResult("{ \"message\": \"Hello JSON\" }")
- .set_header("Content-Type", "application/json");
- }
- }
- void main() {
- var application = new WebApplication(8080);
- application.add_endpoint<HelloEndpoint>(new EndpointRoute("/hello"));
- application.add_endpoint<JsonEndpoint>(new EndpointRoute("/json"));
- application.run();
- }
|