URLDispatcher

URLDispatcher[{patt1content1,patt2content2,}]

represents a dispatcher for deployed URLs that specifies that URLs with relative paths matching the string patterns patti should give content represented by contenti.

Details

  • CloudDeploy[URLDispatcher[]] yields a cloud object corresponding to an active URL dispatcher. All URLs relative to the URL of this cloud object are normally interpreted using the URL dispatcher.
  • Specific deployment of a cloud object to a particular URL, e.g. by CloudDeploy, overrides any rule for that URL given by a URL dispatcher.
  • In the URLs specified by URLDispatcher, the patti are treated as textually appended to the base URL defined by the URL of the deployed URL dispatcher.
  • In CloudDeploy[URLDispatcher[{patt1:>,}]], the patti must start with /.
  • Trailing characters in URLs are by default ignored when the URLs are matched. To force an exact match to the end of a URL, include EndOfString in the string pattern.
  • The contenti must be content suitable for deployment using CloudDeploy.
  • The contenti can contain URLDispatcher.
  • When there are nested URLDispatcher specifications, each successive specification is given whatever trailing part of the URL remains after matching preceding specifications.

Examples

open allclose all

Basic Examples  (2)

URLDispatcher can be used with simple strings:

Visiting https://www.wolframcloud.com/objects/user-b0c28e9f-876d-4478-9d8b-9e7d18a9ea81/application/form yields a FormFunction:

Visiting https://www.wolframcloud.com/objects/user-b0c28e9f-876d-4478-9d8b-9e7d18a9ea81/application/api yields an APIFunction:

Visiting the bare URL of the CloudObject yields a page not found error:

URLDispatcher also supports generic string patterns:

Generalizations & Extensions  (1)

Possible Issues  (3)

URLDispatcher matches when only the first part of the string matches:

Visiting https://www.wolframcloud.com/objects/3329aa63-b811-444c-90c7-29e527aa9eb5/abc?a=foo yields the following:

        

This means that if a substring matches first, the others will be ignored:

This will always go to the welcome page. To avoid this behavior, use an explicit EndOfString:

URLDispatcher requires an explicit "/" when deployed to a CloudObject. The following always returns a 404 error:

The same is not true when URLDispatcher is nested inside another URLDispatcher:

        
Introduced in 2016
 (10.4)