https://github.com/dudelson/shortcake
:cake: Deliciously short URLs
https://github.com/dudelson/shortcake
dudelson-project dudelson-showcase flask python python3 rest-api
Last synced: 2 months ago
JSON representation
:cake: Deliciously short URLs
- Host: GitHub
- URL: https://github.com/dudelson/shortcake
- Owner: dudelson
- License: mit
- Created: 2020-01-19T17:37:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-29T05:18:55.000Z (over 6 years ago)
- Last Synced: 2025-06-04T09:31:34.397Z (about 1 year ago)
- Topics: dudelson-project, dudelson-showcase, flask, python, python3, rest-api
- Language: Python
- Homepage:
- Size: 90.8 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :cake: Shortcake :cake:
**Shortcake** is a URL shortening service. It provides a RESTful API that allows
URLs to be both shortened and lengthened, as well as a simple web interface to
the same functionality. Shortcake can easily be deployed to the cloud, allowing
anyone to host their own URL shortener.
## Shortcake in action
Assuming you're running the development server locally, the API works like this:
``` bash
$ curl -i -H "Content-Type: application/json" -X POST -d '{"url": "http://www.google.com/"}' http://localhost:5000/api/v1/shorten
HTTP/1.0 201 CREATED
Content-Type: application/json
Content-Length: 51
Server: Werkzeug/0.16.0 Python/3.8.1
Date: Wed, 22 Jan 2020 19:41:33 GMT
{"short_url": "http://localhost:5000/qOtlLcV"}
$ curl -i http://localhost:5000/api/v1/lengthen/qOtlLcV
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 38
Server: Werkzeug/0.16.0 Python/3.8.1
Date: Wed, 22 Jan 2020 19:42:23 GMT
{"url": "http://www.google.com/"}
```
It's that simple!
## Deployment
Shortcake is designed to be easily deployed to Heroku. Other cloud deployments
(including docker containers) are unsupported at this time.
To deploy to Heroku, first make sure you're logged in to your Heroku account via
the Heroku CLI. Then, run the following commands in the project root:
``` bash
$ heroku create
$ heroku addons:create heroku-postgresql:hobby-dev
# is the domain of your heroku app as output by `heroku create`
# e.g. shrouded-ocean-06931.herokuapp.com
$ heroku config:set DOMAIN_NAME=""
# generate random data to use as a secret key
$ heroku config:set SECRET_KEY="$(python -c 'import os; print(os.urandom(16))')"
$ git push heroku master
$ heroku open
```
You can then invoke the API against your Heroku instance, or browse to the root
of your Heroku app in your browser to access the web interface.
*Note:* These commands allocate resources within the limits of Heroku's free
tier. Thus an instance setup per the above will run free of charge. If you
decide to upgrade any of the Heroku components, this will no longer be the case.
## Development
If you wish to hack on shortcake yourself, you will find the contents of the
`scripts/` directory useful. In particular, the developer documentation can be
built locally using `scripts/build-docs`, the development server can be run
using `scripts/run-dev`, and the interactive shell instance of the application
can be invoked using `scripts/run-shell`.
Note that both building the docs and running the tests require you to install
the development dependencies via `pipenv install -d`.