https://github.com/pingiun/urlshorten
A super tiny url shortener with a simple API
https://github.com/pingiun/urlshorten
docker docker-compose flask mit-license rest-api url-shortener
Last synced: about 2 months ago
JSON representation
A super tiny url shortener with a simple API
- Host: GitHub
- URL: https://github.com/pingiun/urlshorten
- Owner: pingiun
- License: mit
- Created: 2016-12-17T22:13:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-30T11:11:39.000Z (about 7 years ago)
- Last Synced: 2025-10-20T08:33:19.393Z (8 months ago)
- Topics: docker, docker-compose, flask, mit-license, rest-api, url-shortener
- Language: Python
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# urlshorten
A super tiny url shortener with a simple API
## Running
urlshorten is a simple Flask app, so it can run anywhere you have python.
I also made a Dockerfile and docker-compose.yml if you like containers.
Just run `docker-compose up` if you want to try that out.
If you are testing, you can use requirements-testing.txt because it doesn't
include psycopg2. Then just run `python3 urlshorten.py`, or
`FLASK_APP=urlshorten.py flask run`. Be sure to supply the environment
variables DB_URL and GLOBAL_RATELIMIT as well.
## API
### POST /urls/
#### Parameters
- `url=https://example.com`: The long url you want to shorten
- `secret=false`: Secret urls are longer and hidden from the /urls overview
Returns a json blob that looks like this, where 's' the shortened url:
```json
{
"status": 200,
"message": "s"
}
```
#### Errors
- 400 'Use the argument \`url\`': You didn't supply the url argument
- 400 'Not a valid url': The url wasn't matched by the url regex
- 500 'Some error message': There was an internal error
### GET /urls/
#### Parameters
- `page=1`: The page for the result. (Pages are 25 urls long.)
Returns a list of shortened urls (excluding secret urls) that looks like this:
```json
{
"status": 200,
"message": {
"s": "https://example.com"
}
}
```
#### Errors
- 500 'Some error message': There was an internal error
### GET /urls/\
Returns a the long url for the url_id:
```json
{
"status": 200,
"message": "https://example.com"
}
```
#### Errors
- 404 'Not found': The requested url_id was not found