A URL shortening app for Django.
Project description
django-url-shortening
A custom URL shortening app for Django with API.
Usage
-
Add
urlshorteningapp to yourINSTALLED_APPSand domigrate -
Wire up the redirect view by adding to your URLconf
('^linkshortening/', include('urlshortening.urls')) -
Add settings (more about parameters further)
INITIAL_URL_LEN = 6 RETRY_COUNT = 5 SHORT_URL_PATH = 'http://example.com/short-prefix/' REDIRECT_PREFIX = 'r' -
Now you can use API to make short links
POST linkshortening/short/With json data
{"full_url": "http://example.com/a/b/c/d/e"}And get response
{"data": { "short_id": "123456", "short_url_path": "http://example.com/short-prefix/" }, "error": ""} -
You could also use
urlshorteningright from codefrom urlshortening.models import get_short_url, invalidate_url, get_full_urlurl = "http://example.com/a/b/c/d/e" short_url = get_short_url(url) # Url object print(short_url.short_id) # id for short urlfull_url = get_full_url(short_url.short_id) # Url object print(full_url.url) # "http://example.com/a/b/c/d/e"# You could also invalidate url invalidate_url(full_url.short_id)
API
Get short link
-
URL
/short/ -
Method:
POST -
Data Params
- full_url
-
Success Response:
- Code: 200
Content:{ data: { "short_url_path": "000001" }, error: "" }
- Code: 200
-
Error Response:
-
Code: 400
Content:{ error : "full_url is empty" } -
Code: 400
Content:{ error : "full_url is too long" }
-
Get full link
-
URL
/expand/:short_id/ -
Method:
GET -
URL Params
short_id=[string] -
Success Response:
- Code: 200
Content:{ error : "", data: { full_url: "http://example.com/to-000001" }}
- Code: 200
-
Error Response:
-
Code: 404
Content:{ error : "Link is expired" } -
Code: 404
Content:{ error : "Url doesn\'t exist" }
-
Get redirect
-
URL
/REDIRECT_PREFIX/expand/:short_id/ -
Method:
GET -
URL Params
short_id=[string] -
Success Response:
- Code: 302
- Code: 302
-
Error Response:
-
Code: 404
Content:{ error : "Link is expired" } -
Code: 404
Content:{ error : "Url doesn\'t exist" }
-
Invalidate url
-
URL
/invalidate/ -
Method:
POST -
Data Params
- short_id
-
Success Response:
- Code: 200
Content:{ error : "", data: { "short_id": "000001", "invalidated": "true" } }
- Code: 200
-
Error Response:
-
Code: 400
Content:{ error : "short_id is empty" } -
Code: 400
Content:{ error : "Link is already expired" } -
Code: 404
Content:{ error : "Url doesn\'t exist" }
-
Settings
Available settings are:
-
INITIAL_URL_LENInitial length of short id for url. Once you get more short id's than is possible in all combinations of
INITIAL_URL_LENsymbols it will increase by one -
RETRY_COUNTHow many times do we to check before increasing
INITIAL_URL_LEN. -
SHORT_URL_PATHUrl that will be returned with
short_idonPOST linkshortening/short/request. It might help you to construct full url. -
REDIRECT_PREFIXSelect prefix to use redirect links. For example
REDIRECT_PREFIX="r"and we get redirect links with format/r/expand/{short_id}/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file urlshortening-1.0.0.tar.gz.
File metadata
- Download URL: urlshortening-1.0.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22b9b9e3a4506dd37dd89f9d2c876fe0824ad20eff54836cb55ec2901883d4d8
|
|
| MD5 |
d9c410a6a149adfb3c65517de9cff407
|
|
| BLAKE2b-256 |
0e73b6e6bcb897f46e2a5fbe9058edd169d04b94b0e468b2624d5c834dcf51ad
|
File details
Details for the file urlshortening-1.0.0-py3-none-any.whl.
File metadata
- Download URL: urlshortening-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ea4f7346c4c503c185905a6d1349dc6027167f20af69ad35d499d5d0fab3478
|
|
| MD5 |
74cf94db36d8f54ebb1b44c6bf6ea32b
|
|
| BLAKE2b-256 |
4e5f06fd0baf21d44f7abab2c6ba697e751300471aa76b899299870756d14f51
|