main.nim 1022 B

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