Human-readable URLs


My previous URL schema was /posts/{id:[0-9]}, it was ok for a start. There was a flaw though - it was hard to understand what the post in URL is about by only having numeric IDs.
This is why I’m introducing human-readable URLs, to provide more meaning to the post’s address. AFAIK it is also good for SEO purposes.

So new version of URLs will have following schema /blog/post/{id:[a-zA-Z0-9]}, for example /blog/post/mock_server-5632006343884800.

The implementation is following, post ID is constructed from the sanitised page’s title with the addition of the integer ID at the end to protect it from the clashes.
Sanitising happens in steps:
1. Split Title by space into slice of words
2. Lowercase each word
3. Sanitize each word with the regexes \W+ and \d+ (see in the playground)
4. Concat each word with underscores (_)