skip to Main Content

Arriving URL format https://my-apim.azure-api.net/product/service1/v3/service1/operation. Client library prefix second "service1" to the URL, my base URL: "https://my-apim.azure-api.net/product/service1/" , version – v3, operation – "/operation". Because of second "service1" in the URL APIM can’t find matching API operation.

I have added rewrite-uri to the inbound Policies to remove second "service1", so it can match operation:

<rewrite-uri template="@(context.Request.OriginalUrl.Path.ToString().Replace("service1/operation", "operation"))" copy-unmatched-params="true" />

It didn’t help.
I did try to debug/trace it. It looks like matching to operation comes before rewrite-uri policy and it will always return 404. In the trace API and version are matched correct, but not operation.
Snippet from trace output:

{
                "source": "api-inspector",
                "timestamp": "2024-09-05T07:12:38.9153327Z",
                "elapsed": "00:00:00.0003329",
                "data": {
                    "configuration": {
                        "api": {
                            "from": "/product/service1",
                            "to": null,
                            "version": "v3",
                            "revision": "1"
                        },
                        "operation": "-",
                        "user": "-",
                        "product": {
                            "id": "product"
                        }
                    }
                }
            },

If operation is matched, the uri-write works as expected.
How can I modify URI before it is matched to API and operation?

EDIT:
backend URL format: https://server1.contoso.com/service1/

2

Answers


  1. Chosen as BEST ANSWER

    The policy is not going to work here because operation is not identified from URL. The suggestion from Microsoft support was to use header or query parameter based versioning. Then version is no longer in URL. Not the best solution, but the only I can work with.


  2. Generally, APIM Base URL format looks like https://{apimInstanceName}.azure-api.net. So, If you will create a new API by providing the details as given below then the endpoint would be in the required format https://{apimInstanceName}.azure-api.net/product/service1/v3/operation when created.

    enter image description here

    Then, you need to add an operation by providing URL template value as /operation to get the desired endpoint format.

    enter image description here

    While testing, I am not getting 404 error and its correctly hitting the backend URL.

    enter image description here

    I have noticed, to attribute in api-inspector is null in your case. It will be null if you haven’t configured backend URL, even I have tried it by deleting the backend URL.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search