{"id":21354352,"url":"https://github.com/samestrin/url-shortening-api-vercel","last_synced_at":"2026-05-05T19:33:32.897Z","repository":{"id":240445181,"uuid":"801307664","full_name":"samestrin/url-shortening-api-vercel","owner":"samestrin","description":"A Node.js Vercel infrastructure (Vercel Functions, Vercel KV, and Vercel Postgres) based URL shortener REST API. Used by https://frwrd.ing/.","archived":false,"fork":false,"pushed_at":"2024-06-11T20:57:56.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-25T20:47:30.376Z","etag":null,"topics":["functions","nodejs","redis","url-shortener","vercel","vercel-functions","vercel-kv","vercel-postgres"],"latest_commit_sha":null,"homepage":"https://frwrd.ing/","language":"JavaScript","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/samestrin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-16T01:32:38.000Z","updated_at":"2024-06-11T20:57:59.000Z","dependencies_parsed_at":"2024-05-18T23:25:54.500Z","dependency_job_id":"3fa8d46f-482d-4b8d-b2b8-934e9f01dceb","html_url":"https://github.com/samestrin/url-shortening-api-vercel","commit_stats":null,"previous_names":["samestrin/url-shortening-api-vercel"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/samestrin/url-shortening-api-vercel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Furl-shortening-api-vercel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Furl-shortening-api-vercel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Furl-shortening-api-vercel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Furl-shortening-api-vercel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samestrin","download_url":"https://codeload.github.com/samestrin/url-shortening-api-vercel/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Furl-shortening-api-vercel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32665040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["functions","nodejs","redis","url-shortener","vercel","vercel-functions","vercel-kv","vercel-postgres"],"created_at":"2024-11-22T04:13:12.188Z","updated_at":"2026-05-05T19:33:32.880Z","avatar_url":"https://github.com/samestrin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# url-shortening-api-vercel\n\n[![Star on GitHub](https://img.shields.io/github/stars/samestrin/url-shortening-api-vercel?style=social)](https://github.com/samestrin/url-shortening-api-vercel/stargazers)[![Fork on GitHub](https://img.shields.io/github/forks/samestrin/url-shortening-api-vercel?style=social)](https://github.com/samestrin/url-shortening-api-vercel/network/members)[![Watch on GitHub](https://img.shields.io/github/watchers/samestrin/url-shortening-api-vercel?style=social)](https://github.com/samestrin/url-shortening-api-vercel/watchers)\n\n![Version 0.0.2](https://img.shields.io/badge/Version-0.0.2-blue)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)[![Built with Node.js](https://img.shields.io/badge/Built%20with-Node.js-green)](https://nodejs.org/)\n\nurl-shortening-api-vercel is a URL shortener service. It is a serverless application that provides URL shortening and retrieval functionalities. Utilizing the Vercel infrastructure - Vercel Functions, Vercel KV (Redis), and Vercel Postgres, the application offers a high performance, efficient and scalable solution for creating, serving, and tracking short URLs that redirect to the original, longer URLs.\n\n### Why Vercel Infrastructure\n\nThis project now uses Vercel because they are a single provider for all project infrastructure needs, including Vercel Functions, Vercel KV (Redis), and Vercel Postgres. Migrating to Vercel has reduced latency caused by historical Netlify/Supabase interactions and allowed for using Vercel KV (Redis) as a caching layer.\n\nPlease note, moving from Netlify Edge Functions to Vercel Functions reduces the number of function executions to 100k/month. If you need more executions, the legacy [Netlify Edge version](https://github.com/samestrin/url-shortening-api-netlify-edge-supabase) of this API may still be a better choice.\n\n_This replaces the legacy [url-shortening-api-netlify-edge-supabase](https://github.com/samestrin/url-shortening-api-netlify-edge-supabase) project due to a number of performance improvements._\n\n## Features\n\n- **URL Shortening**: Convert long URLs into short, manageable links.\n- **URL Validation**: Ensures that only valid URLs with proper protocols are processed.\n- **Redirection**: Automatically redirect users from the short URL to the original long URL.\n- **Latest Links Retrieval**: Fetch the most recently shortened URLs.\n- **URL Count**: Retrieve the total number of URLs shortened.\n- **API Version Information**: Obtain the current version of the API.\n- **CORS Support**: Handles Cross-Origin Resource Sharing to enable API access from different domains.\n- **Error Handling**: Graceful error responses for various error scenarios.\n\n## Dependencies\n\n- **Node.js**: JavaScript runtime environment\n- **Vercel**: Hosting platform for serverless functions\n- **PostgreSQL (Vercel Postgres)**: Relational database for storing URL data\n- **Redis (Vercel KV)**: Key-Value store for caching\n- **formidable**: Library for parsing form data\n- **valid-url**: Utility for URL validation\n- **dotenv**: Environment variable management\n\n## Installing Node.js\n\nBefore installing, ensure you have Node.js and npm (Node Package Manager) installed on your system. You can download and install Node.js from [Node.js official website](https://nodejs.org/).\n\n## Installing url-shortening-api-vercel\n\n1.  **Clone the Repository**\n\n```bash\ngit clone https://github.com/samestrin/url-shortening-api-vercel.git\ncd url-shortening-api-vercel\n```\n\n2.  **Install Dependencies**\n\n```bash\nnpm install\n```\n\n3.  **Set Up PostgreSQL Database**\n\nCreate your Postgres database.\n\nRun the SQL script to create necessary tables and insert initial data using the Vercel Storage interface.\n\n4.  **Set Up KV (Redis)**\n\nCreate your KV database.\n\n5.  **Configure Environment Variables**\n\nCreate a `**.env**` file in the root directory and add the following variables:\n\n```bash\nPOSTGRES_URL=your_postgres_connection_string\nKV_REST_API_URL=your_kv_rest_api_url\nKV_REST_API_TOKEN=your_kv_rest_api_token\nURLSHORT_URL_BASE=your_base_url (Example: http://frwrd.ing/)\nURLSHORT_TRACK_CLICKS=true_or_false\nURLSHORT_RESOLVE_HOSTNAME=true_or_false URLSHORT_DEFAULT_IP_ADDRESS_ID=default_ip_address_id URLSHORT_DEFAULT_HOSTNAME_ID=default_hostname_id\nURLSHORT_DEFAULT_USER_ID=default_user_id\n```\n\n6.  **Deploy to Vercel**\n\n```bash\nvercel deploy\n```\n\n## Endpoints\n\n### Shorten URL\n\n**Endpoint:** `/shorten` **Method:** POST\n\nShorten a long URL and return the shortened URL.\n\n- `url`: The URL to be shortened.\n\n#### **Example Usage**\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n  https://localhost/shorten \\\n  -H 'Content-Type: application/x-www-form-urlencoded' \\\n  --data-urlencode 'url=https://www.google.com'\n```\n\nThe server responds with:\n\n```bash\n{\"shortUrl\":\"lqywv6P\"}\n```\n\n### Forward URL\n\n**Endpoint:** `/[shortId]` **Method:** GET\n\nBased on shortened URL, e.g. `/lqywv6P` HTTP 301 forward to a long url.\n\nThis endpoint is accessed by navigating directly to the shortened URL.\n\n#### **Example Usage**\n\nUse curl to make a request:\n\n```bash\ncurl http://localhost/[shortId]\n```\n\n### Retrieve Latest Shortened Links\n\n**Endpoint:** `/latest` **Method:** GET\n\nRetrieve the latest URLs shortened.\n\nThis endpoint is accessed by navigating directly to /latest.\n\n#### **Example Usage**\n\nUse curl to make a request:\n\n```bash\ncurl http://localhost/latest\n```\n\n### Retrieve Count\n\n**Endpoint:** `/count` **Method:** GET\n\nRetrieve the number of URLs shortened.\n\nThis endpoint is accessed by navigating directly to /count.\n\n#### **Example Usage**\n\nUse curl to make a request:\n\n```bash\ncurl http://localhost/count\n```\n\n### Retrieve Version\n\n**Endpoint:** `/version` **Method:** GET\n\nRetrieve the current version of the API.\n\nThis endpoint is accessed by navigating directly to /version.\n\n#### **Example Usage**\n\nUse curl to make a request:\n\n```bash\ncurl http://localhost/version\n```\n\nThe server responds with:\n\n```bash\n{\n    \"name\": \"url-shortening-api-vercel\",\n    \"version\": \"0.0.2\",\n    \"description\": \"url-shortening-api-vercel is a URL shortener service using the Vercel infrastructure - Vercel Functions, Vercel KV (Redis), and Vercel Postgres.\",\n    \"author\": \"Sam Estrin\",\n    \"homepage\": \"https://github.com/samestrin/url-shortening-api-vercel#readme\"\n}\n```\n\n## CORS\n\nThe server responds with appropriate CORS headers such as Access-Control-Allow-Origin.\n\n## Error Handling\n\nThe API handles errors gracefully and returns appropriate error responses:\n\n- **400 Bad Request**: Invalid request parameters.\n- **404 Not Found**: Resource not found.\n- **405 Method Not Allowed**: Invalid request method (not GET or POST).\n- **500 Internal Server Error**: Unexpected server error.\n\n## Contribute\n\nContributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Share\n\n[![Twitter](https://img.shields.io/badge/X-Tweet-blue)](https://twitter.com/intent/tweet?text=Check%20out%20this%20awesome%20project!\u0026url=https://github.com/samestrin/url-shortening-api-vercel) [![Facebook](https://img.shields.io/badge/Facebook-Share-blue)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/samestrin/url-shortening-api-vercel) [![LinkedIn](https://img.shields.io/badge/LinkedIn-Share-blue)](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/samestrin/url-shortening-api-vercel)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamestrin%2Furl-shortening-api-vercel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamestrin%2Furl-shortening-api-vercel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamestrin%2Furl-shortening-api-vercel/lists"}