DEV Community

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

Posted on

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)