{"id":18878312,"url":"https://github.com/captaincluster/url-shortener-microservice","last_synced_at":"2025-04-14T18:32:11.620Z","repository":{"id":238706749,"uuid":"796911372","full_name":"CaptainCluster/URL-Shortener-Microservice","owner":"CaptainCluster","description":"The third project for the \"Back End Development and APIs\" course provided by FreeCodeCamp. ","archived":true,"fork":false,"pushed_at":"2024-05-07T15:44:49.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-20T12:47:03.569Z","etag":null,"topics":["backend","expressjs","freecodecamp","freecodecamp-project","microservice"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CaptainCluster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T21:14:16.000Z","updated_at":"2024-09-26T07:27:12.000Z","dependencies_parsed_at":"2024-05-07T17:02:55.175Z","dependency_job_id":null,"html_url":"https://github.com/CaptainCluster/URL-Shortener-Microservice","commit_stats":null,"previous_names":["captaincluster/url-shortener-microservice"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCluster%2FURL-Shortener-Microservice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCluster%2FURL-Shortener-Microservice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCluster%2FURL-Shortener-Microservice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptainCluster%2FURL-Shortener-Microservice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptainCluster","download_url":"https://codeload.github.com/CaptainCluster/URL-Shortener-Microservice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248936856,"owners_count":21186115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","expressjs","freecodecamp","freecodecamp-project","microservice"],"created_at":"2024-11-08T06:25:53.393Z","updated_at":"2025-04-14T18:32:11.363Z","avatar_url":"https://github.com/CaptainCluster.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener Microservice\n\n![Express.js](https://img.shields.io/badge/express.js-%23404d59.svg?style=for-the-badge\u0026logo=express\u0026logoColor=%2361DAFB)\n\nURL Shortener Microservice is the 3rd project for FreeCodeCamp *Back End Development and APIs* course. A post request allows the reception of the URL\nsent by the user and the allocation of an index. The index can then be used in a GET request, allowing a redirection to a page with a single number.\n\n🙏 Credits\n---\n![FreeCodeCamp](https://img.shields.io/badge/Freecodecamp-%23123.svg?\u0026style=for-the-badge\u0026logo=freecodecamp\u0026logoColor=green)\n\nEverything **not** written by me has been cloned from [this GitHub repository](https://github.com/freeCodeCamp/boilerplate-project-urlshortener/).\n\nThe default README that comes with the cloned repository:\n\u003e This is the boilerplate code for the URL Shortener Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice.\n\nHere is the solution I wrote for this project:\n```\nconst bodyParser = require(\"body-parser\");\napp.use(bodyParser.urlencoded({ extended: false }));\n\nconst existingUrls = [];\n\napp.post(\"/api/shorturl\", function(req, res, next)\n{\n  // Making sure the url is valid at first\n  if(!req.body.url.includes(\"http\"))\n  {\n    return res.json({\n      error: \"invalid url\"\n    });\n  }\n\n  next();   //Continuing with a valid url\n},\nfunction(req, res)\n{\n  if(existingUrls.includes(req.body.url))\n  {\n    return res.json({\n      url: req.body.url,\n      index: existingUrls.indexOf(req.body.url) + 1\n    });\n  }\n\n  existingUrls.push(req.body.url);\n\n  res.json({\n    original_url: req.body.url,\n    short_url: existingUrls.indexOf(req.body.url) + 1\n  });\n});\n\napp.get(\"/api/shorturl/:shortUrl\", function(req, res)\n{\n  if(existingUrls.length \u003c req.params.shortUrl)\n  {\n    return res.json({\n      error: \"invalid url\"\n    });\n  }\n  res.redirect(existingUrls[Number(req.params.shortUrl) - 1]); \n});\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptaincluster%2Furl-shortener-microservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaptaincluster%2Furl-shortener-microservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptaincluster%2Furl-shortener-microservice/lists"}