Search code examples
parametersplayframeworkrequestslug

How to de-slugify a request URL before the action is executed in Play! Framework


I'm always slugyfing my links, so that for example:

http://site.com/this%20is%20a%20link

becomes:

http://site.com/this-is-a-link

I would like to de-slugify the request URL before any action is processed, so that for example if I have the following route configured:

GET /{parameter}   Controller.action

And I invoke a slugyfied link like:

/this-is-a-link

The parameter is processed as "this is a link" instead of "this-is-a-link".

Any tips?

EDIT: Maybe the replacement of the values must be done before the Router actually routes the request.


Solution

  • Slugs are meant to be saved in the database along with what they point to. Creating a slug is a one-way transformation. There is no such thing as "de-slugify" as multiple characters get translated into the same character.

    You should handle possible collisions by adding a number suffix or something similar.