Why Nim 🤔
Nim is powerful programming language that compiles into C, Cpp, ObjC and JS.
You can install it here
HappyX ✨
HappyX is an asynchronous web framework, written in Nim.
Source code
We'll work with it.
nimble install happyx
Getting Started 👔
You should create project. Choose project name and mark project type as SSG
.
hpx create
You should move into project folder after this.
cd PROJECT_NAME/src
Development 🛠
Let's launch project.
nim c -r main
Also you can use flags -d:httpx
and -d:micro
to use alternative HTTP servers.
Let's change main.nim
. For it you should open src/
folder and open main.nim
file. You will see 👀
import happyx
serve("127.0.0.1", 5000):
get "/":
"Hello, world!"
Rewrite this 👨🔬
import happyx
# Go to http://127.0.0.1:5000/ 👨🔬
serve("127.0.0.1", 5000):
# Assignment counter
var counter = 0
# You can open / in your browser and see result 🍍
get "/":
inc counter
# Return string
"counter = {counter}"
# You can open /upd or /upd100 in your browser and see result 🍍
get "/upd{i?:int}":
counter += i
"counter = {counter}"
And recompile 🛠
That's all! Good Luck! 🙂
Also you can read about SPA in Nim
Top comments (0)