Skip to content

Getting started

Ethosa edited this page Mar 15, 2020 · 1 revision

As you already know, Akane is an asynchronous web framework written in Nim. Let's try to write our first web application on it. Create a separate folder for this.

Now create the main.nim file and write the following into it:

import akane

proc main() =
  let server = newServer("127.0.0.1", 5000, debug=true)

  server.pages:
    equals("/"):
      await request.answer("Hello, world!")
  
  server.start()
main()

Now we should make out what we wrote in general, right?

import akane - I think everything is clear here, but if not: this is an import of the library that needed to be installed.

proc main() = - This is necessary because server.start requires the gcsafe function without using global variables.

let server = newServer("127.0.0.1", 5000, debug=true) - Here we created a new server instance with the address "127.0.0.1", port 5000 and debug mode enabled.

server.pages - This is a macro that makes adding new pages easier.

equal("/") - Here we literally say: "when the user is at http://127.0.0.1:5000/"

await request.answer("Hello, world!") - This will send a response from the server.

server.start() and main() - I don’t think it needs an explanation.

Clone this wiki locally