SimpleApi.vala 581 B

12345678910111213141516171819
  1. using Astralis;
  2. using Invercargill;
  3. void main() {
  4. var router = new Router();
  5. var server = new Server(8080, router);
  6. router.map_get("/hello", (context) => {
  7. print("Handling /hello\n");
  8. return new BufferedHttpResult.from_string("Hello from Astralis!");
  9. });
  10. router.map_get("/json", (context) => {
  11. print("Handling /json\n");
  12. return new BufferedHttpResult.from_string("{ \"message\": \"Hello JSON\" }", StatusCode.OK, Iterate.single<HttpHeader>(new HttpHeader("Content-Type","application/json")));
  13. });
  14. server.run();
  15. }