shlink icon indicating copy to clipboard operation
shlink copied to clipboard

Support "path prefix" on short url creation

Open Javaru opened this issue 2 years ago • 1 comments

Summary

We'd like for Shlink to generate/create multi-segment slugs for us (as opposed to multi-segment custom slugs) by being able to provide a slug prefix. To do this, we'd like to see an enhancement made to the /rest/v{version}/short-urls POST endpoint for creating short URLs that allows for setting a slug prefix. This can be used to generate multi-segment slugs. Or just to have a slug contain a prefix.

Currently, to create a multi-segment slug, you must provide the full custom slug. This adds implementation burden on the client to create unique slugs rather than depending on Shlink's capabilities & features, and configurations. Rather than setting a complete custom slug, we'd like to set a multi-segment prefix, say via a slugPrefix property (name can be flushed out) on the POST request. Shlink would then create a multi-segment slug of https://exam.ple/{slugPrefix}{generatedSlug}

For example, for the request

{
  "longUrl": "https://subdomain.example.com/foo/bar",
  "title": "Example Page",
  "slugPrefix": "docs/"
}

would generate a URL of https://exam.ple/docs/abc123 where abc123 is a slug generated by Shlink.

For those that might prefer hyphens or other formatting, "slugPrefix": "docs-" would generate https://exam.ple/docs-abc123. And "slugPrefix": "FOO" would generate https://exam.ple/FOOabc123.

In the event a slugPrefix and a customSlug is provided, I would expect the behavior to be to create a URL of https://exam.ple/{slugPrefix}{customSlug}. This seems the most straight forward way to handle that use case. And allows the flexibility when generating multi-segment slugs in code. For example, the code may want to always use a specific slugPrefix, while typically having Shlink generate the (suffix) slug (and thus not set customSlug) but in some circumstances may want to provide a specific (suffix) slug, and would thus set customSlug to the desired (suffix) slug.

Use case

We need to generate URLs both within our application, which has web-app, Apple, and Android UI clients, and our business website. Our mobile apps need to internally determine if the short URL is one the App needs to handle directly, displaying the requested data or feature in the app, or if it is one to forward to the mobile device's web browser for display. The cleanest way to do this for us to do this is to use multi-segmented slugs. For example https://exam.ple/app/abc123 gets handled by the mobile app directly, and https://exam.ple/web/abc123 is forwarded to the browser. (We'd likely use shorter single character "prefixes", but for illustrative purposes app and web work.)

Currently to do this, our clients will need to generate full custom slugs when creating a short URL. This adds a lot of implementation complexity as we need to generate those slugs in a way that guarantees uniqueness across multiple running instances. In effect, taking over a core responsibility from Shlink.

Another use cases would be when it is desired to have some human (and/or machine) recognizably in a short URL. For example https://exam.ple/Dxxxxxx is a link to documentation, https://exam.ple/Pxxxxxx is a link to a product, and https://exam.ple/Qxxxxxx is a link to a FAQ.

Javaru avatar Sep 29 '23 15:09 Javaru

Yeah, this sounds like a useful feature

acelaya avatar Sep 29 '23 15:09 acelaya

This is now implemented and will be released with Shlink 4.0.0

acelaya avatar Feb 21 '24 18:02 acelaya