Cannot pass any test case of URL SHORTENER

Hey,
I am unable to pass any of the test cases given in the problem statement but the code is working perfectly fine, it is shortening the URL by giving a unique ID and by passing that ID , it is redirecting the to target page correctly. I have no idea why the test cases are not passing.
Attaching my code below for your reference:
https://5URLShortenerMicroservice.parasj08.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: URL Shortener Microservice

Link to the challenge:

When I try to POST from your app, looking in the network tab of the dev tools, I see:

Request:

Request URL: https://5urlshortenermicroservice.parasj08.repl.co/api/shorturl/new
Request Method: POST
Body: url: https://en.wikipedia.org/wiki/Antoni_Gaud%C3%AD

Response:

{"original_url":"https://en.wikipedia.org/wiki/Antoni_Gaud%C3%AD","short_url":"yrg9h7_4s"}

When I do the same for the sample app, I get:

Request:

Request URL: https://url-shortener-microservice.freecodecamp.rocks/api/shorturl
Request Method: POST
Body: url: https://en.wikipedia.org/wiki/Antoni_Gaud%C3%AD

Response:

{"original_url":"https://en.wikipedia.org/wiki/Antoni_Gaud%C3%AD","short_url":5841}

There is one critical difference there. Do you see it?

does short_url have to be all numeric?

I don’t think so. I think I did a base 64 when I did my version of it. That isn’t the difference I was trying to point out.

all I notice is the short_url is not in string form

Yes, I see that, too. Again, that is not what I think the issue is.

What is it then? I dont see any more difference

The instructions say:

You can POST a URL to /api/shorturl …

What url are you posting to?

Part of being a dev is developing the skill to focus on tiny details.

1 Like

OMG, cant believe I did that, Thank you so much!!!

That’s part of being a dev. Even after you develop good “dev detective” skills, it still sometimes happens. Before the apocalypse, when we were still in offices, my cubical mate and I would sometimes have to turn to each other, “I’m sure it’s something simple, but I can’t get this to work. What am I missing?”

But still, developing those detective skills is good. I try to explain my investigative process as I go - please take a look and make sure that you understand what I did.

As your working with APIs, besides the browser dev tools, something like Postman is also a useful tool to get used to.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.