DEV Community

Cover image for RestAPI Request Models In Nim πŸ‘‘
Ethosa
Ethosa

Posted on

1

RestAPI Request Models In Nim πŸ‘‘

HappyX provides request models since v0.20.0

You could also saw request models in Fastapi

Model declaring πŸ› 

model MyModel:
  param1: string
  param2: int = 100  # you can use default values 🍍
Enter fullscreen mode Exit fullscreen mode

Model usage 🎈

get "/[m:MyModel]":  # you can't use model as arg name because model is macro
  echo m.param1
  echo m.param2
  req.answer { "response": {
    "one": m.param1,
    "two": m.param2
  }}
Enter fullscreen mode Exit fullscreen mode

And you can send GET request using Postman:
http://......./
with JSON body:

{
  "param1": "123"
  "param2": 2
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay