An alternative using URL Rewriter and Visualforce pages
One of the features available to us within a Salesforce site is the option to rewrite incoming URLs to the site to allow more user- and SEO-friendly URLs to be used. A typical example is one where if our site was hosting a blog, rather than using the more standard Salesforce URL /blog?id=1234567890bloghere
, which is not SEO- or user-friendly, we would use /blog/2020/02/14/why-apex-developers-are-the-best-partners
. We do this using a class that implements the Site.UrlRewriter
interface.
Sadly, this interface does not work with API endpoints and so cannot be used to redirect our Apex REST APIs. There is a workaround for this though, which is to return our JSON data via a Visualforce page.
Note
This is a workaround and is not the optimal way of handling these requirements. This will only work for GET
requests for JSON data and not the other HTTP methods. I am including it here as it is a known workaround and has some use...