0
votes

I have a frontend url say - 'https:\test.helloweb.com\account' which is defined a post request /person and I want to direct any request that comes on that url to a backend url like so 'https:\secure.hiddenapi\vi\api\person'.

The above scenario is easy and works now the place where I'm stuck is if there is a request for

Say -

  1. /person/<id>/membership
  2. /person/<id>/membership/<memid>
  3. /person/<id>/accountdetails/

these requests needs to be directed to

  1. https:\\secure.hiddenapi\vi\api\person\<id>\membership
  2. https:\\secure.hiddenapi\vi\api\person\<id>\membership\<memid>
  3. https:\\secure.hiddenapi\vi\api\person\<id>\accountdetails.

I tried defining the operation as /person/* then if i make a request to /person/<id>/membership then the backend url called is https:\\secure.hiddenapi\vi\api\person\membership without the id.

Seems like a simple issue but cannot make any progress!

2

2 Answers

0
votes

Try using rewrite URL policy to route to different backend URL for specific operation as follows:

<inbound>
<base />
<rewrite-uri template="/accountdetails/" />
</inbound>
0
votes

Here is how APIM maps URLs. Consider:

  1. An API with:
    • API URL suffix set to "myapi"
    • Web service URL set to "https://contoso.com/api"
  2. An operation with:
    • URL template: "/myoperation"

When APIM receives a request it will split it into two parts:

https://service.azure-api.net/myapi/myoperation
^                                   ^
API base URL                        operation path

It will then replace API base URL with "Web service URL" specified for matched API and this will become request to backend:

https://contoso.com/api/myoperation

In your case, given that you end up with "person/person" it is likely you have "person" in both Web service URL and operation URL template. So you have two options.

First option is to configure Web service URL as "https://secure.hiddenapi/vi/api" and let all your operation templates start with "/person".

Another way is to set service URL as "https://secure.hiddenapi/vi/api/person" and do not include "/person" into your operation URL templates. It's perfectly fine if operation URL template starts with a variable like "{id}/membership/{memid}".

It's a good practice to split your whole backend API into different APIs in APIM for control and management. So personally I'd prefer first option, and if later there would be a need to make request to backend with prefix different than "/person" I'd create another API.