https://github.com/hrkings/url-shortener
https://github.com/hrkings/url-shortener
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hrkings/url-shortener
- Owner: HRKings
- Created: 2021-12-17T17:50:12.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-26T19:47:15.000Z (about 2 years ago)
- Last Synced: 2024-12-27T13:23:06.787Z (5 months ago)
- Language: Go
- Size: 110 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URL Shortener
This is a simple URL shortener written in Go, it features a Redis cache with a 3-day TTL and a click logger with persistent storage in PostgreSQL
# Running
## Shell
Create a `.env` file with the necessary values (with can be found in the example), and execute the `run.sh`## Docker
Using docker-compose, run the following
```bash
docker-compose -f docker-compose.yml -f docker-compose.run.yml up -d
```# API Specification
_An OpenAPI specification can be found under the `assets` directory in the root of this repository_
The service only has two endpoints:
## POST `/`
Used to shorten an URL, accepts a JSON body containing a `url` property with the URL to be shortened
Example:
```json
{
"url": "https://github.com/HRKings/url-shortener",
"fallback": "https://example.com", // (Optional) Optional fallback URL for when the short link expires
"ttl": "72" // (Optional) TTL in hours of the link
}
```## GET `/:short_url`
Redirects the user to the original URL
## PUT `/:short_url`
Add the shortUrl into REDIS (will redirect again)
### PUT `/:short_url?ttl=EXPIRATION_IN_HOURS`
Optionally the query param `ttl` can be sent to set the cache expiration of this link
## DELETE `/:short_url`
Remove the shortUrl from REDIS (will not redirect anymore)
# SQL Structure
_A SQL script to create the tables can be found under the `assets` directory in the root of this repository_
