A Url shortener microservice made during FreeCodeCamp Back End Development and APIs course.
- Use dns module
- Post a url in /api/shorturl and get a response with original_url and short_url
- When you visit /api/shorturl/<short_url>, you will be redirected to the original URL.
- If you pass an invalid URL need return { error: 'invalid url' }
You have 2 example of request in app.http you could use REST Client ou another tool.
POST
https://url-shortener-uzv4.onrender.com/api/shorturl
Content-Type: application/x-www-form-urlencoded
// A url form encoded
url=https://edlavio.eu.org
GET
// After shorturl/put_here_short_url
https://url-shortener-uzv4.onrender.com/api/shorturl/534447
// Open in Browser and will redirect to https://github.com/Edlavio
You will need pnpm and Node.js and some API test tool (Postman, Imsomnia, Thunder Client, Httpie or REST Client).
You will need also setup a Mongo Database and create a .env file you have .env.sample as example.
# To install the dependencies
pnpm i
# To run de project
pnpm dev