Let's code the URL-shortening service to explain all the concepts we discussed in the preceding section. We need a few basics before writing an API for our service. First, we need to design a package that implements the Base62 algorithm with encoding/decoding functions. The URL-shortening technique needs the Base62 algorithm to convert a long URL to a short one, and vice versa. After designing the package, we'll write an example to show how this encoding works.
Implementing a URL-shortening service using PostgreSQL and pq
Defining the Base62 algorithm
The Base62 algorithm is a number encoder that converts a given number to a string. How does it do that? The input number is mapped from 62 characters. The beauty of...