main.nim 1.0 KB

123456789101112131415161718192021
  1. # author: Ethosa
  2. # equals, startswith, endswith, notfound and regex.
  3. import akane
  4. var server = newServer(debug=true)
  5. server.pages:
  6. equals("/helloworld"): # when url is "domain/helloworld"
  7. await request.answer("Hello, World!")
  8. startswith("/get"): # when url is "domain/get...", try "domain/get100000"
  9. await request.answer("I see only \"" & url & "\"") # url var, contains text after "/get".
  10. endswith("/info"): # when url is ".../info", try "domain/user/info"
  11. await request.answer("I see only \"" & url & "\"") # url var, contains text before "/info".
  12. regex(re"\A\/id(\d+)\z"): # when url is re"domain/id\d+", try "domain/id123" and "domain/idNotNumber"
  13. await request.answer("Hello, user with ID" & url[0]) # url var contains array[20, string], matched from URL.
  14. notfound: # `notfound` should be at the end of the remaining cases
  15. await request.error("<h1 align='center'>Sorry, but page not found :(</h1>") # `error` sends Http404 code.
  16. server.start() # Starts server.