SimpleApi.vala 660 B

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