Url patterns

Services will often need to connect to other services as part of their function. In this case, generally we will want to forward some of the parameter data sent to the original request to the service being called. An example would be the Authentication service. This needs to determine a url on which it can retrieve the full user record for the user who just logged in. It has a configuration parameter 'userUrlPattern' which is set to a string containing a url pattern which it uses to find the user. A common setting would be:

/json/user/${email}

The ${email} is a standard substitution code saying take the email property from the data sent to the original request and insert it here.

The substitutions available follow a standard system across Restspace based on splitting up the url path elements into sections. For example:

/auth/impersonate/bert@something.com / with-roles

  • /auth here is the base path: the path from the site root on which the service is mounted. The service handles any request with a path starting /auth.
  • /impersonate/bert@something.com/with-roles is the service path - this is the rest of the path after the base path.
  • /impersonate is the main path: in this case it specifies the function to perform within the auth nanoservice.
  • /bert@something.com/with-roles is the sub path, the rest of the service path after the main path. In this case it specifies the parameters for impersonation.

Substitution codes available are as below:

  • $>1 is the second element from the left of the service path.
  • $<2<0 is the second last to the last element of the service path inclusive.
  • $>1<0:(home) is the service path except for its leftmost element, or 'home' if the service path is empty.
  • $* is a special shorthand for the whole service path.
  • $B<0 is the last element of the base path.
  • $S>0 is the first element of the sub path.
  • $?(email) is the value of the query string item 'email'.
  • ${abc.xyz} is the value of subproperty xyz of property abc of the related data (usually the post data of the original request). A special syntax here allows you to write for instance ${abc.arr[]}. This will read the array property abc.arr and create a new url output for each value in the array. Multiple substitutions like this will create a url for each possible combination of array values. This is called array substitution and only works in certain contexts.


Substitution codes

Substition codes construct a url from another url (the context url). Most commonly the substitution codes will be substituted by elements of the url on which the service was originally called.

Service path elements

These substitions refer to elements of the context url's service path.

  • $* is a special shorthand for the whole service path.
  • $>0 is the leftmost element of the service path, $>1 the next to the right etc.
  • $<0 is the rightmost element of the service path, $<1 the next to the left etc.
  • $>0<1 is the service path from its leftmost element to the second from the right inclusive
  • $<1<0 is the service path from its second rightmost element to the rightmost element inclusive

Base path, sub path and name elements

These substitutions work in the same way as