Azure API管理 - 返回JSON响应而无需发送到后端服务

发布于 2025-02-13 10:45:40 字数 122 浏览 0 评论 0原文

我正在尝试在Azure API管理中创建一个API,我只想设置一个简单的API,该API返回具有200个状态的JSON响应,而无需将其发送到任何后端服务。 我通过嘲笑找到了一种方法,但想知道是否有更好的方法。

谢谢,

I am trying to create an API in Azure API Management where I just want to set up a simple API that returns a JSON response with a 200 status without sending it to any backend services.
I found a way to do this through mocking but wondering if there is a better approach to this.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2025-02-20 10:45:40

我通过在入站处理中添加策略来弄清楚这一点:

<policies>
    <inbound>
        <base />
        <return-response>
            <set-status code="200" />
            <set-header name="Content-Type" exists-action="override">
                <value>application/json</value>
            </set-header>
            <set-body>{
                "test_key": "hello"
            }</set-body>
        </return-response>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

I have figured this out by adding the policy in Inbound Processing:

<policies>
    <inbound>
        <base />
        <return-response>
            <set-status code="200" />
            <set-header name="Content-Type" exists-action="override">
                <value>application/json</value>
            </set-header>
            <set-body>{
                "test_key": "hello"
            }</set-body>
        </return-response>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文