| 123456789101112131415161718192021222324252627282930313233343536 |
- using Astralis;
- using Invercargill;
- using Invercargill.DataStructures;
- // Simple handler for /hello endpoint
- class HelloEndpoint : Object, Endpoint {
- public string route { get { return "/hello"; } }
- public Method[] methods { owned get { return { Method.GET };} }
- public async HttpResult handle_request(HttpContext http_context, RouteInformation route) throws Error {
- print("Handling /hello\n");
- return new HttpStringResult("Hello from Astralis!");
- }
- }
- // Simple handler for /json endpoint
- class JsonEndpoint : Object, Endpoint {
- public string route { get { return "/json"; } }
- public Method[] methods { owned get { return { Method.GET };} }
- public async HttpResult handle_request(HttpContext http_context, RouteInformation route) throws Error {
- print("Handling /json\n");
- return new HttpStringResult("{ \"message\": \"Hello JSON\" }")
- .set_header("Content-Type", "application/json");
- }
- }
- void main() {
- var router = new EndpointRouter()
- .add_endpoint(new HelloEndpoint())
- .add_endpoint(new JsonEndpoint());
-
- var pipeline = new Pipeline()
- .add_component(router);
- var server = new Server(8080, pipeline);
- server.run();
- }
|