Gabriele Ferro Home

APIs and Microservices Project - URL Shortener

Day 96: 10 December 2020

**Today’s Progress:**

Very little progress today... but I learned a lot!

Today I have started the URL Shortener Microservice project on freeCodeCamp and I have immediately faced multiple challenges.

So I peeked at the suggestions (but not at the solution!) because I wanted to have more advices on desired functionality. ¯\_(ツ)_/¯

The project concerns the creation of the backend that allows the user to post an URL, and then get a corresponding shorter URL.

The POST request will create a database entry that contains the original url and the shorter one.

When the user insert the shorter URL, the GET request for that specific path will find the corresponding entry in the database and it will redirect the user to the desired page.

The project already includes a few useful modules like dotenv, cors and express and it suggests to include body-parser aswell to handle the POST request. We will also need to use a database, in particular MongoDB so we need mongoose module. Since I prefer a Mongoose validation error instead of MongoDB, I included mongoose-unique-validator.

In addition an old friend is back to the rescue for this job.

StackOverflow:

I have started to build a schema for our model.

* The mongoose unique validator does not work for this project and I will probably remove it.

Then I installed and imported all the modules I needed, I connected the backend to the mongoDB database using dotenv and mongoose then I added the body-parser middleware.

For the route POST, where there is an empty line, I will the write the code that check if the entry already exists in our database and in that case it will be returned. Otherwise, a new entry will be created in our database. In any case, we will receive a response in JSON format with both URLs.

For now, this code does not handle the case of duplicates but returns a poor error instead of providing the existing database entry.

Moreover, I still have to write the GET route to perform the redirection.

**Thoughts:**

Luckily, months ago I made the decision to use all this time profitably by:

  • signing up for OpenClassRooms to get a valid certificate in France as Web Developer
  • completing freeCodeCamp full stack curriculum.

But even if I don't do work & study anymore because I am now in full confinement for a few months, I'm starting to get mentally tired and emotionally devastated.

I'm sure I'm not the only one.

**Link to tweet:**

[twitter-follow screen_name='20Gabriele20']

May 2024
MTWTFSS
 12345
6789101112
13141516171819
20212223242526
2728293031 

Archives

Gabriele Ferro Home
Copyright © Ferro Gabriele. All rights reserved.