DEV Community

Cover image for Woo.vi - Building Woovi Shortener Microservice
Sibelius Seraphini for Woovi

Posted on

Woo.vi - Building Woovi Shortener Microservice

Every successful Startup has a cool shortener service.
Woovi is no different, we have woo.vi 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('https://woovi.com');
  }

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

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

    return;
  }

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

  ctx.redirect(`${shortener.url}${queryString}`);
};
Enter fullscreen mode Exit fullscreen mode

If no shortid was passed, we are going to return woovi.com, this is the logic that redirect woo.vi to woovi.com.

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 woo.vi link for you: https://woo.vi/nMfr8wekO4AI


Woovi
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)