Ain't me in the photo. Just an Unsplash one...
As my next project, I decided to build a url-shortener. I Googled how other folks had done it and I started to read very complicated posts, which made me very confused. I decided to stop reading and plung into the code (like the one in the photo!). I put some thought on the architecture. I even draw some charts! Nothing too fancy, no worries. The architecture I went with is the follow, please give me feedback of any sort if you think I could do better!
- User types a url client side.
- I pass this url to the server in the body.
- The server grabs the body and stores it in a row of the database alongside a randomly generated string of characters.
- The server returns this random string to the client and it displays it back to the User (i.e. bit.ly/{whatever the random string}
- Cool, now the User can go and post it in places. Once someone hits domain.whatever/{randomly generated string} the following happens.
- domain.whatever is a React app. I use
useEffect()
and it has an API call to the server, passing the randomly generated string as url parameter. - The server grabs the parameter, looks it up in the database, fetches the real url, returns it to the client.
- The client redirects from domain.whatever/{randomly generated string} to the full url that is returned from the server.
Voilà! Please, give me feedback. Thanks for reading!