Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "path prefix" on short url creation #1884

Closed
Javaru opened this issue Sep 29, 2023 · 2 comments · Fixed by #2020
Closed

Support "path prefix" on short url creation #1884

Javaru opened this issue Sep 29, 2023 · 2 comments · Fixed by #2020
Labels
Milestone

Comments

@Javaru
Copy link

Javaru commented Sep 29, 2023

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 Javaru added the feature label Sep 29, 2023
@Javaru Javaru changed the title Enhance 'create short URL' REST API endpoint to allow setting a multi-segment prefix Enhance 'create short URL' REST API endpoint to allow setting a (multi-segment) prefix Sep 29, 2023
@acelaya
Copy link
Member

acelaya commented Sep 29, 2023

Yeah, this sounds like a useful feature

@acelaya acelaya changed the title Enhance 'create short URL' REST API endpoint to allow setting a (multi-segment) prefix Support "path prefix" on short url creation Sep 29, 2023
@acelaya acelaya added this to the 4.0.0 milestone Nov 4, 2023
@acelaya acelaya moved this to Todo in Shlink Feb 1, 2024
@acelaya acelaya moved this from Todo to In Progress in Shlink Feb 19, 2024
@acelaya acelaya mentioned this issue Feb 21, 2024
1 task
@acelaya acelaya moved this from In Progress to In review in Shlink Feb 21, 2024
@github-project-automation github-project-automation bot moved this from In review to Done in Shlink Feb 21, 2024
@acelaya
Copy link
Member

acelaya commented Feb 21, 2024

This is now implemented and will be released with Shlink 4.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants