Friendly URLs for Assets

Oftentimes an asset is all that’s needed to render a whole page, such as a blog post. In situations like that, it would be nice to have the URL of the web page contain the title of the blog.

Suppose I have a blog post titled “Morning Starts with Coffee”. I would want the URL of the page that shows this blog post to be something like https://..../blog-morning-starts-with-coffee.html. This is very easy to accomplish with Oracle Content and Experience because you can enable friendly URLs for content types.

Once friendly URLs are enabled for a content type, a new field is added to assets of that type. Furthermore, Oracle Content and Experience automatically populates the friendly URL field with the asset name. As soon as I create a blog asset, its "Friendly Item Name for URL"—also called slug in the API—shows the name of the asset (with some automatic character replacements for better URL handling).

Of course, you can change this friendly URL to anything you want. Oracle Content and Experience handles all the necessary validations to make sure it’s unique.


Description of friendly_urls-png.png follows
Description of the illustration friendly_urls-png.png

This slug field is now part of the asset’s data. When you get this asset (say, from a search list), you can fetch the slug field and use that in your client to construct the URL of a page.

More interestingly, Oracle Content and Experience provides a way to fetch the asset using just the slug value. For example, instead of accessing this blog asset with

https://.../content/published/api/v1.1/items/COREB6795E95BE27481690961D6657D5B70E?channelToken=83e8e3bc1f5f55f9b02a8183622589ad

you can use the slug in the URL:

https://.../content/published/api/v1.1/items/.by.slug/blog-morning-starts-with-coffee?channelToken=83e8e3bc1f5f55f9b02a8183622589ad

This means that if the slug of an asset is in the URL of a page, all that the client needs to do is grab that string and request the underlying asset by slug. This saves a round trip to look up or search for an asset with a slug and then fetch its assets.

It’s useful to note that every variation of the API that exists for an /items/{id} also exists for /items/.by.slug/{value}. These two APIs are therefore equivalent from the perspective of the content delivery API.