{"id":20555335,"url":"https://github.com/srgrr/urlshortener","last_synced_at":"2026-04-15T19:41:35.939Z","repository":{"id":204207059,"uuid":"564334036","full_name":"srgrr/URLShortener","owner":"srgrr","description":"URL shortener to practice a little bit","archived":false,"fork":false,"pushed_at":"2023-03-11T18:56:31.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T06:33:51.987Z","etag":null,"topics":["docker","experiment","fastapi","learning-by-doing","learning-exercise","memcached","nginx","pymemcache","pytest","python","redis","redis-client","uvicorn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srgrr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-11-10T13:50:37.000Z","updated_at":"2023-03-23T15:22:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"3546b762-0d32-4d50-816f-fc85c0a079c8","html_url":"https://github.com/srgrr/URLShortener","commit_stats":null,"previous_names":["srgrr/urlshortener"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/srgrr/URLShortener","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srgrr%2FURLShortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srgrr%2FURLShortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srgrr%2FURLShortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srgrr%2FURLShortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srgrr","download_url":"https://codeload.github.com/srgrr/URLShortener/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srgrr%2FURLShortener/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31857621,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["docker","experiment","fastapi","learning-by-doing","learning-exercise","memcached","nginx","pymemcache","pytest","python","redis","redis-client","uvicorn"],"created_at":"2024-11-16T03:18:00.500Z","updated_at":"2026-04-15T19:41:35.920Z","avatar_url":"https://github.com/srgrr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URLShortener\nYet another implementation of the classical URL Shortener.\n\n## How to use it\n```\npython -m server.rest --configuration-file \u003cpath-to-file\u003e\n```\n`rest` folder contains a `configuration.ini` file with a sample configuration.\n\n`FastAPI` generates a swagger interface that can be accessed in `localhost:port`. \n\n## Containerization\nRun `docker build -t shortener .` in the root of the repository.\n\nThen `docker run -p port:port shortener` should do the trick\n\nIf you want to use a custom configuration file you can do it with\n\n```\ndocker run -v path/to/file/folder/:/config \\\n-p port:port \\\nshortener\n```\n\nMake sure your configuration file is named `configuration.ini`\n\nIt will overwrite the configuration file right before starting the container\n\n## Available storage methods\n\nURL mappings can either be stored in files or in Redis. Both systems have the following common configuration paramters\n\n```\nimplementation=redis|files\nmax_generation_retries=10\nurl_length=3\nurl_pool=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n```\n\nNames are kind of self-explanatory I think.\n\n### Filesystem\nMeant for testing purposes. Stores all entries in a file.\n\n### Redis\nStore all short url mappings in a Redis instance, requires the following configuration parameters\n```\nhost=localhost\nport=6379\nusername=root\npassword=root\nbucket_size=16384\n```\nRedis will convert all the URLs to numbers in base `pool_size`.\n\nA short url with number `N` will belong to bucket `N // num_buckets`.\n\nIf `bucket_size = 128` we will only need to check 128 positions to find a suitable candidate for a new, randomly generated short url.\n\nTODO: Vanity doesn't update bucket info, it will throw a 500 error, but it won't prevent the service from picking that particular bucket again\nTODO: Two concurrent processes might end up choosing the same random URL. Whoever wrote it the last will get the right mapping (maybe add bucket-key locking?)\n\n## Local env\nYou can make the access to your local shortener service more convenient by changing `/etc/hosts` and using a reverse proxy.\n\nFor example, you can access to the service via browser as `s.es` by adding this entry to `/etc/hosts`\n\n```\n127.0.0.1 s.es\n```\n\nAnd starting an `nginx` instance with this configuration\n\n```\nevents {\n  worker_connections 1024;\n}\nhttp {\n server {\n   listen 80;\n\n   server_name s.es;\n \n   location / {\n       proxy_pass http://localhost:8080;\n   }\n }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrgrr%2Furlshortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrgrr%2Furlshortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrgrr%2Furlshortener/lists"}