DEV Community

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

Posted on • Edited on

8

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (1)

Collapse
 
brosmaninho profile image
Diário do BRO • Edited

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

Best regards!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up