You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

apiary.io能否回显请求数据?如何配置接口返回对应请求数据?

Hey there! Let's break down your Apiary.io questions clearly:

1. Does Apiary.io support echoing request data?

Absolutely! Apiary has built-in support for dynamically echoing request data in responses using its templating system (powered by MSON syntax extensions). You don't have to stick to hardcoded responses—you can pull values directly from incoming requests and inject them into your response payloads.

2. How to make your Create User endpoint return request-matching data?

The issue right now is that your response is hardcoded, so it spits out the same payload no matter what you send. To fix this, you'll need to replace those fixed values with template variables that reference the request body.

Here's how to update your Create User endpoint Blueprint:

### Create a User [POST]
+ Request (application/json; charset=utf-8)
    {
        "user_id": 1053,
        "username": "demo@demo.com",
        "email": "demo@demo.com",
        "active": "true"
    }
+ Response 201 (application/json)
    {
        "user_id": {{request.body.user_id}},
        "username": {{request.body.username}},
        "email": {{request.body.email}},
        "active": {{request.body.active}}
    }

What's happening here?

  • The {{request.body.fieldName}} syntax tells Apiary to grab the value of fieldName from the incoming request's JSON body and drop it into the response. Just make sure the field names match exactly (they're case-sensitive!).
  • If you want to handle optional fields or set defaults, you can add simple logic. For example, if active might be missing from the request, you could use {{request.body.active || "false"}} to fall back to a default value.

Once you save this updated Blueprint, test the endpoint again—any valid JSON you send in the request should now be reflected in the 201 response.

内容的提问来源于stack exchange,提问作者Brian McCord

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:20:21