DEV Community

Cover image for Writing Simple RestAPI in Nim With HappyX #1
Ethosa
Ethosa

Posted on • Edited on

Writing Simple RestAPI in Nim With HappyX #1

In this tutorial series we create RestAPI in Nim using HappyX web framework ✌

Getting Started 🔨

At first we need to install Nim lang

After this via nimble we install HappyX 🔌

nimble install happyx@#head 
Enter fullscreen mode Exit fullscreen mode

I will edit my code with VS Code ✌

Project Creation 🛠

Just run this command

hpx create --name:tutorial --kind:SSG cd tutorial/src 
Enter fullscreen mode Exit fullscreen mode

Hello, world! ✌

Let's open tutorial/src/main.nim
You'll see this (without comments)

import # This will import HappyX framework happyx # Setting up our server at `127.0.0.1:5000` serve("127.0.0.1", 5000): # on GET HTTP method at 127.0.0.1:5000/ get "/": # We'll see "Hello, world!" "Hello, world!" 
Enter fullscreen mode Exit fullscreen mode

Let's rename route

 # on GET HTTP method at 127.0.0.1:5000/hello-world get "/hello-world": 
Enter fullscreen mode Exit fullscreen mode

Now let's try it 🎈

nim c -r -d:debug main 
Enter fullscreen mode Exit fullscreen mode

Open browser and go to http://localhost:5000/hello-world 🥳

Source code

Top comments (1)

Collapse
 
brosmaninho profile image
Diário do BRO • Edited

Great tutorial.
I just started in Nim/HappyX world.

Best regards!