Costin_T
Costin_T

Reputation: 786

Azure API Management - Can I define a custom response status code?

When setting up the all the possible response codes and their descriptions for an endpoint in API Management Service, I can only choose an existing status code from a dropdown list, but it doesn't allow me to add a custom status code, such as 499. I use the 499 status code in my API for a specific type of error relevant to my applicatoin. Is there any way to add this to the list of responses?

enter image description here

Upvotes: 0

Views: 2479

Answers (2)

Vitaliy Kurokhtin
Vitaliy Kurokhtin

Reputation: 7795

Not with forms UI. But if you select an API, there'll be a pencil in Frontend block on Design tab. It allows you to edit your API specification in OpenAPI 2/3 spec. Using that it should be possible to add a custom response statuses code.

Upvotes: 0

Joey Cai
Joey Cai

Reputation: 20067

You could dynamic mocking using APIM with an APIM policy called return-response.

<return-response>
    <set-status code="200" reason="OK" />
    <set-header name="content-type" exists-action="override">
        <value>"application/json"</value>
    </set-header>
    <set-body>{
        "id": "cat12345",
        "name": "Garfield",
        "tag": "Sleepy Cat"
    }</set-body>
</return-response>

For more details, you could refer to this tutorial.

Upvotes: 1

Related Questions