|
1 | 1 | # url-shortening-api-netlify-edge-supabase |
2 | 2 |
|
| 3 | +[](https://github.com/samestrin/url-shortening-api-netlify-edge-supabase/stargazers)[](https://github.com/samestrin/url-shortening-api-netlify-edge-supabase/network/members)[](https://github.com/samestrin/url-shortening-api-netlify-edge-supabase/watchers) |
| 4 | + |
| 5 | +[](https://opensource.org/licenses/MIT)[](https://nodejs.org/) |
| 6 | + |
3 | 7 | url-shortening-api-netlify-edge-supabase is a URL shortener service. It is a serverless application that provides URL shortening and retrieval functionalities. Utilizing Netlify Edge Functions and Supabase, a cloud-based database, the application offers a high performance, efficient and scalable solution for creating short URLs that redirect to the original, longer URLs. |
4 | 8 |
|
5 | | -This replaces the legacy [url-shortening-api-netlify-supabase](https://github.com/samestrin/url-shortening-api-netlify-supabase) project. |
| 9 | +This replaces the legacy [url-shortening-api-netlify-edge-supabase](https://github.com/samestrin/url-shortening-api-netlify-edge-supabase) project. |
| 10 | + |
| 11 | +### **Features** |
| 12 | + |
| 13 | +- **URL Shortening**: Convert long URLs into short, manageable links that are easier to share. |
| 14 | +- **URL Validation**: Ensures that only valid URLs with proper protocols are processed. |
| 15 | +- **Automatic URL Deduplication**: Checks the database to avoid storing duplicate entries for the same URL. |
| 16 | +- **High Performance**: Leveraging Netlify Edge Functions combined with the Supabase REST API for high-speed data retrieval and storage. |
| 17 | +- **Error Handling**: Robust error handling mechanisms to provide clear feedback on the nature of issues encountered. |
| 18 | + |
| 19 | +## Endpoints |
| 20 | + |
| 21 | +### Shorten URL |
| 22 | + |
| 23 | +**Endpoint:** `/shorten` **Method:** POST |
| 24 | + |
| 25 | +Shorten a long URL and return the shortened URL. |
| 26 | + |
| 27 | +- `url`: The URL to be shortened. |
| 28 | + |
| 29 | +#### **Example Usage** |
| 30 | + |
| 31 | +Use a tool like Postman or curl to make a request: |
| 32 | + |
| 33 | +```bash |
| 34 | +curl -X POST \ |
| 35 | + https://localhost/shorten \ |
| 36 | + -H 'Content-Type: application/x-www-form-urlencoded' \ |
| 37 | + --data-urlencode 'url=https://www.google.com' |
| 38 | +``` |
| 39 | + |
| 40 | +The server responds with: |
| 41 | + |
| 42 | +```bash |
| 43 | +{"shortUrl":"lqywv6P"} |
| 44 | +``` |
| 45 | + |
| 46 | +### Forward URL |
| 47 | + |
| 48 | +**Endpoint:** `/[shortId]` **Method:** GET |
| 49 | + |
| 50 | +Based on shortened URL, e.g. `/lqywv6P` HTTP 301 forward to a long url. |
| 51 | + |
| 52 | +This endpoint is accessed by navigating directly to the shortened URL. |
| 53 | + |
| 54 | +#### **Example Usage** |
| 55 | + |
| 56 | +Use curl to make a request: |
| 57 | + |
| 58 | +```bash |
| 59 | +curl http://localhost/[shortId] |
| 60 | +``` |
| 61 | + |
| 62 | +### Retrieve Latest Shortened Links |
| 63 | + |
| 64 | +**Endpoint:** `/latest` **Method:** GET |
| 65 | + |
| 66 | +Retrieve the latest URLs shortened. |
| 67 | + |
| 68 | +This endpoint is accessed by navigating directly to /latest. |
| 69 | + |
| 70 | +#### **Example Usage** |
| 71 | + |
| 72 | +Use curl to make a request: |
| 73 | + |
| 74 | +```bash |
| 75 | +curl http://localhost/latest |
| 76 | +``` |
| 77 | + |
| 78 | +### Retrieve Count |
| 79 | + |
| 80 | +**Endpoint:** `/count` **Method:** GET |
| 81 | + |
| 82 | +Retrieve the number of URLs shortened. |
| 83 | + |
| 84 | +This endpoint is accessed by navigating directly to /count. |
| 85 | + |
| 86 | +#### **Example Usage** |
| 87 | + |
| 88 | +Use curl to make a request: |
| 89 | + |
| 90 | +```bash |
| 91 | +curl http://localhost/count |
| 92 | +``` |
| 93 | + |
| 94 | +### Retrieve Version |
| 95 | + |
| 96 | +**Endpoint:** `/version` **Method:** GET |
| 97 | + |
| 98 | +Retrieve the current version of the API. |
| 99 | + |
| 100 | +This endpoint is accessed by navigating directly to /version. |
| 101 | + |
| 102 | +#### **Example Usage** |
| 103 | + |
| 104 | +Use curl to make a request: |
| 105 | + |
| 106 | +```bash |
| 107 | +curl http://localhost/version |
| 108 | +``` |
| 109 | + |
| 110 | +## CORS |
| 111 | + |
| 112 | +The server responds with appropriate CORS headers such as Access-Control-Allow-Origin. |
| 113 | + |
| 114 | +## Error Handling |
| 115 | + |
| 116 | +The API handles errors gracefully and returns appropriate error responses: |
| 117 | + |
| 118 | +- **400 Bad Request**: Invalid request parameters. |
| 119 | +- **404 Not Found**: Resource not found. |
| 120 | +- **405 Method Not Allowed**: Invalid request method (not GET or POST). |
| 121 | +- **500 Internal Server Error**: Unexpected server error. |
| 122 | + |
| 123 | +## Contribute |
| 124 | + |
| 125 | +Contributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements. |
| 126 | + |
| 127 | +## License |
| 128 | + |
| 129 | +This project is licensed under the MIT License - see the LICENSE file for details. |
| 130 | + |
| 131 | +## Share |
| 132 | + |
| 133 | +[](https://twitter.com/intent/tweet?text=Check%20out%20this%20awesome%20project!&url=https://github.com/samestrin/url-shortening-api-netlify-edge-supabase) [](https://www.facebook.com/sharer/sharer.php?u=https://github.com/samestrin/url-shortening-api-netlify-edge-supabase) [](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/samestrin/url-shortening-api-netlify-edge-supabase) |
0 commit comments