dynamic path parameter extraction from URL

Not applicable

I have dynamic path parameter in base path as well as in resource path

base path : /student/{student_id}

resource path : /class/{class_number}

When I mention the variable name itself in the path,I dont expect to use additional extract variable policy to extract using request.path or URI.path.

But I am not able to use the variables student_id,class_number directly in other policies without using extract variable policy.

Then is there any difference in mentioning the base path and resource path with variable name in it rather than using as /student/* and /class/* ?

0 3 827
3 REPLIES 3

You need to use Extract Variables policy to retrieve path params -

http://docs.apigee.com/api-services/reference/extract-variables-policy [see the URI sample]

> When I mention the variable name itself in the path,I dont expect to use additional extract variable policy - unfortunately, this is not true

> is there any difference in mentioning the base path and resource path with variable name in it rather than using as /student/* and /class/* ?

there is no difference in functionality - just that the variables are not populated to the context automatically.

Thanks @Mukundha Madhavan

Could you please cite one example on "

just that the variables are not populated to the context automatically.

"?

For extracting specific sections of the URI, you need to use an Extract Variable policy.

When you define the path with a variable, the variable will be automatically populated after applying the Extract Variable policy. For e.g. with the below configuration, urirequest.id will be automatically populated with the actual value.

<ExtractVariables name="ExtractVariables-1">
   <DisplayName>Extract a portion of the url path</DisplayName>
   <Source>request</Source>
   <URIPath>
      <Pattern ignoreCase="true">/accounts/{id}</Pattern>
   </URIPath>
   <VariablePrefix>urirequest</VariablePrefix>
   <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

Another e.g.

<ExtractVariables name="ExtractVariables-1">
   <Source>request</Source>
   <URIPath>
      <Pattern ignoreCase="true">/a/{pathSeg1}/c/{pathSeg2}</Pattern>
   </URIPath>
   <VariablePrefix>urirequest</VariablePrefix>
   <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>

When you use the above configuration with the URL

http://myCo.com/employees/XYZ/hr/leaves 

The urirequest.pathSeg1 variable is set to "XYZ" and the urirequest.pathSeg2 variable is set to "leaves".

You use * when you want to do wildcard match -

<URIPath>
  <Pattern ignoreCase="true">/a/*/{id}</Pattern>
  <Pattern ignoreCase="true">/a/**/{id}</Pattern>
</URIPath>

The first pattern matches URIs such as "/a/b/c", "/a/foo/bar", etc. The second pattern matches any number of path segments after "/a/", such as "/a/foo/bar/baz/c", as well as "/a/b/c" and "/a/foo/bar".

Hope this helps!