Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vividvilla/lil
Simple URL shortener built with Go
https://github.com/vividvilla/lil
Last synced: 11 days ago
JSON representation
Simple URL shortener built with Go
- Host: GitHub
- URL: https://github.com/vividvilla/lil
- Owner: vividvilla
- Created: 2019-07-10T08:56:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-24T05:52:18.000Z (over 4 years ago)
- Last Synced: 2023-05-14T21:00:46.556Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 41
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lil
Simple URL shortener based on Go.
## API
### Redirect
`GET /` - Redirects to target URL.
### Redirect page
`GET /p/` - HTML page which redirects to target url. Page additionally renders
OpenGraph tags specified while creating short url. Useful for sharing
previewable link in social media sites.### Create a short url
`POST /api/new` - Create a random short url for given url, accepts JSON post body.
#### Params
- `url` - Target url to redirect.
- `title` - Page title used in paged redirect.
- `og_tags` - List of Open graph tags to be used in paged redirect.
- `property` - Open graph property tag
- `content` - Open graph content tag#### Response
Response returns short uri ID, redirect url and page redirect url.
```json
{
"data": {
"id": "",
"url": "http://localhost/",
"page": "http://localhost/p/"
}
}
```### Get redirect links
`GET /api/` - Get redirect links for given short uri.
#### Response
Response returns short uri ID, redirect url and page redirect url.
```json
{
"data": {
"id": "",
"url": "http://localhost/",
"page": "http://localhost/p/"
}
}
```### Delete a short url
`DELETE /api/` - Delete a give short url.
#### Response
```json
{
"data": true
}
```## Examples
### Create a short url
```
# Request
curl -X "POST" "http://localhost:8085/api/new" \
-H 'Content-Type: text/plain; charset=utf-8' \
-d $'{
"url": "https://zerodha.com",
"title": "Zerodha",
"og_tags": [
{"property": "og:image", "content": "https://zerodha.com/static/images/kite-dashboard.png"}
]
}'# Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8{
"data": {
"id": "72p9abOM",
"url": "http://localhost:8085/72p9abOM",
"page": "http://localhost:8085/p/72p9abOM"
}
}
```### Direct redirect
```
# Request
curl http://localhost:8085/72p9abOM# Response
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: https://zerodha.comMoved Permanently.
```### Page redirect
```
# Page redirect which renders additional open graph data.
curl http://localhost:8085/p/72p9abOM# Response
HTTP/1.1 200 OK
Date: Thu, 18 Jul 2019 08:14:03 GMTZerodha
window.location.replace("https:\/\/zerodha.com");
```
### Get redirect links
```
# Request
curl "http://localhost:8085/api/72p9abOM"# Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8{
"data": {
"id": "72p9abOM",
"url": "http://localhost:8085/72p9abOM",
"page": "http://localhost:8085/p/72p9abOM"
}
}
```# Delete a short url
```
# Request
curl -X "DELETE" "http://localhost:8085/api/72p9abOM"# Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8{
"data": true
}
```## Backend store
Currently Redis is the only backend store available but new stores can be easily
added by implementing [store interface](store/store.go), for example here is the
[Redis store implementation](store/redis/store.go).## TODO
- Basic auth for create and delete APIs. Currently this can be implemented
behind reverse proxy like Nginx or API gateways like Kong, AWS API gateway.
- Custom path for short URLs instead of random generated paths.
- Redirect stats.