DEV Community

Cover image for - Building Woovi Shortener Microservice
Sibelius Seraphini for Woovi

Posted on - Building Woovi Shortener Microservice

Every successful Startup has a cool shortener service.
Woovi is no different, we have as our shortener domain.

Benefits of a shortener domain

A short domain is easier to remember.
They are more suitable for SMS and social media where character limits are strict, like Twitter.
It can improve brand recognition.
They offer link analytics.
They increase CTR - Click-through rates.
Furthermore, they can redirect to other links.

Building Woovi Shortener Microservice

Here is a basic code of a shortener endpoint using Koa:

export const shortIdUrlGet = async (ctx: Context) => {
  const { id } = ctx.params;

  if (!id) {
    return ctx.redirect('');

  const shortener = await Shortener.findOne({
    shortId: id,

  if (!shortener?.url) {
    ctx.body = {
      error: 'Not found',


  const queryString = ctx.querystring ? `?${ctx.querystring}` : '';

Enter fullscreen mode Exit fullscreen mode

If no shortid was passed, we are going to return, this is the logic that redirect to

When passing a valid id we redirect to saved url in the Shortener model in our mongodb database.
We also forward querystring.

To generate the shortid, we use the open source package NanoId

In Conclusion

A shortener domain has many benefits, and your Startup should invest it to have one. The implementation is simple, it is just a key value mapping.

Here is a link for you:

Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.

If you want to work with us, we are hiring!

Photo by Michael Dziedzic on Unsplash

Top comments (0)