urlshortening


Nameurlshortening JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/Enkompass/django-urlshortening
SummaryA URL shortening app for Django.
upload_time2024-09-07 22:40:42
maintainerNone
docs_urlNone
authorEnkompass
requires_pythonNone
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            django-url-shortening
=====================
A custom URL shortening app for Django with API.

Usage
=====
1. Add ``urlshortening`` app to your ``INSTALLED_APPS`` and do ``migrate``

2. Wire up the redirect view by adding to your URLconf
    ```
    ('^linkshortening/', include('urlshortening.urls'))
    ```

3. Add settings (more about parameters further)
    ```
    INITIAL_URL_LEN = 6
    RETRY_COUNT = 5
    SHORT_URL_PATH = 'http://example.com/short-prefix/'
    REDIRECT_PREFIX = 'r'
    ```

4. 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": ""}
    ```

5. You could also use ``urlshortening`` right from code
    ```
    from urlshortening.models import get_short_url, invalidate_url, get_full_url
    ```
    ```
    url = "http://example.com/a/b/c/d/e"
    short_url = get_short_url(url) # Url object
    print(short_url.short_id) # id for short url
    ```
    ```
    full_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 <br />
      **Content:** `{ data: { "short_url_path": "000001" }, error: "" }`
 
- **Error Response:**

    - **Code:** 400 <br />
      **Content:** `{ error : "full_url is empty" }`

    - **Code:** 400 <br />
      **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 <br />
      **Content:** `{ error : "", data: { full_url: "http://example.com/to-000001" }}`
 
- **Error Response:**

    - **Code:** 404 <br />
      **Content:** `{ error : "Link is expired" }`

    - **Code:** 404 <br />
      **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 <br />
 
- **Error Response:**

    - **Code:** 404 <br />
      **Content:** `{ error : "Link is expired" }`

    - **Code:** 404 <br />
      **Content:** `{ error : "Url doesn\'t exist" }`
    
**Invalidate url**

- **URL**
    ```
    /invalidate/
    ```

- **Method:** `POST`
  
- **Data Params**

    - short_id
  
- **Success Response:**

    - **Code:** 200 <br />
      **Content:** `{ error : "", data: { "short_id": "000001", "invalidated": "true" } }`
 
- **Error Response:**

    - **Code:** 400 <br />
      **Content:** `{ error : "short_id is empty" }`

    - **Code:** 400 <br />
      **Content:** `{ error : "Link is already expired" }`
    
    - **Code:** 404 <br />
      **Content:** `{ error : "Url doesn\'t exist" }`

        
Settings
========

Available settings are:

- ``INITIAL_URL_LEN``
    
    Initial length of short id for url. Once you get more short id's than is possible in all combinations of ``INITIAL_URL_LEN`` symbols it will increase by one

- ``RETRY_COUNT``
    
    How many times do we to check before increasing ``INITIAL_URL_LEN``.

- ``SHORT_URL_PATH``
    
    Url that will be returned with ``short_id`` on ``POST linkshortening/short/`` request. It might help you to construct full url.
    
- ``REDIRECT_PREFIX``

    Select prefix to use redirect links. For example ``REDIRECT_PREFIX="r"`` and we get redirect links with format  ``/r/expand/{short_id}/``
   

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Enkompass/django-urlshortening",
    "name": "urlshortening",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Enkompass",
    "author_email": "jvazquez@enkompass.net",
    "download_url": "https://files.pythonhosted.org/packages/0e/73/b6e6bcb897f46e2a5fbe9058edd169d04b94b0e468b2624d5c834dcf51ad/urlshortening-1.0.0.tar.gz",
    "platform": null,
    "description": "django-url-shortening\n=====================\nA custom URL shortening app for Django with API.\n\nUsage\n=====\n1. Add ``urlshortening`` app to your ``INSTALLED_APPS`` and do ``migrate``\n\n2. Wire up the redirect view by adding to your URLconf\n    ```\n    ('^linkshortening/', include('urlshortening.urls'))\n    ```\n\n3. Add settings (more about parameters further)\n    ```\n    INITIAL_URL_LEN = 6\n    RETRY_COUNT = 5\n    SHORT_URL_PATH = 'http://example.com/short-prefix/'\n    REDIRECT_PREFIX = 'r'\n    ```\n\n4. Now you can use API to make short links\n    \n    ``POST linkshortening/short/``\n    \n    With json data ``{\"full_url\": \"http://example.com/a/b/c/d/e\"}``\n\n    And get response\n    ```\n    {\"data\": {\n        \"short_id\": \"123456\",\n        \"short_url_path\": \"http://example.com/short-prefix/\"\n     }, \"error\": \"\"}\n    ```\n\n5. You could also use ``urlshortening`` right from code\n    ```\n    from urlshortening.models import get_short_url, invalidate_url, get_full_url\n    ```\n    ```\n    url = \"http://example.com/a/b/c/d/e\"\n    short_url = get_short_url(url) # Url object\n    print(short_url.short_id) # id for short url\n    ```\n    ```\n    full_url = get_full_url(short_url.short_id) # Url object\n    print(full_url.url) # \"http://example.com/a/b/c/d/e\"\n    ```\n    ```\n    # You could also invalidate url\n    invalidate_url(full_url.short_id)\n    ```\n\n\nAPI\n===\n**Get short link**\n\n- **URL**\n    ```\n    /short/\n    ```\n\n- **Method:** `POST`\n\n- **Data Params**\n    - full_url\n\n- **Success Response:**\n    - **Code:** 200 <br />\n      **Content:** `{ data: { \"short_url_path\": \"000001\" }, error: \"\" }`\n \n- **Error Response:**\n\n    - **Code:** 400 <br />\n      **Content:** `{ error : \"full_url is empty\" }`\n\n    - **Code:** 400 <br />\n      **Content:** `{ error : \"full_url is too long\" }`\n    \n**Get full link**\n\n- **URL**\n    ```\n    /expand/:short_id/\n    ```\n\n- **Method:** `GET`\n  \n- **URL Params**\n    ```\n    short_id=[string]\n    ```\n\n- **Success Response:**\n\n    - **Code:** 200 <br />\n      **Content:** `{ error : \"\", data: { full_url: \"http://example.com/to-000001\" }}`\n \n- **Error Response:**\n\n    - **Code:** 404 <br />\n      **Content:** `{ error : \"Link is expired\" }`\n\n    - **Code:** 404 <br />\n      **Content:** `{ error : \"Url doesn\\'t exist\" }`\n    \n**Get redirect**\n\n- **URL**\n    ```\n    /REDIRECT_PREFIX/expand/:short_id/\n    ```\n\n- **Method:** `GET`\n  \n- **URL Params**\n    ```\n    short_id=[string]\n    ```\n\n- **Success Response:**\n\n    - **Code:** 302 <br />\n \n- **Error Response:**\n\n    - **Code:** 404 <br />\n      **Content:** `{ error : \"Link is expired\" }`\n\n    - **Code:** 404 <br />\n      **Content:** `{ error : \"Url doesn\\'t exist\" }`\n    \n**Invalidate url**\n\n- **URL**\n    ```\n    /invalidate/\n    ```\n\n- **Method:** `POST`\n  \n- **Data Params**\n\n    - short_id\n  \n- **Success Response:**\n\n    - **Code:** 200 <br />\n      **Content:** `{ error : \"\", data: { \"short_id\": \"000001\", \"invalidated\": \"true\" } }`\n \n- **Error Response:**\n\n    - **Code:** 400 <br />\n      **Content:** `{ error : \"short_id is empty\" }`\n\n    - **Code:** 400 <br />\n      **Content:** `{ error : \"Link is already expired\" }`\n    \n    - **Code:** 404 <br />\n      **Content:** `{ error : \"Url doesn\\'t exist\" }`\n\n        \nSettings\n========\n\nAvailable settings are:\n\n- ``INITIAL_URL_LEN``\n    \n    Initial length of short id for url. Once you get more short id's than is possible in all combinations of ``INITIAL_URL_LEN`` symbols it will increase by one\n\n- ``RETRY_COUNT``\n    \n    How many times do we to check before increasing ``INITIAL_URL_LEN``.\n\n- ``SHORT_URL_PATH``\n    \n    Url that will be returned with ``short_id`` on ``POST linkshortening/short/`` request. It might help you to construct full url.\n    \n- ``REDIRECT_PREFIX``\n\n    Select prefix to use redirect links. For example ``REDIRECT_PREFIX=\"r\"`` and we get redirect links with format  ``/r/expand/{short_id}/``\n   \n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "A URL shortening app for Django.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Enkompass/django-urlshortening"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e5f06fd0baf21d44f7abab2c6ba697e751300471aa76b899299870756d14f51",
                "md5": "74cf94db36d8f54ebb1b44c6bf6ea32b",
                "sha256": "0ea4f7346c4c503c185905a6d1349dc6027167f20af69ad35d499d5d0fab3478"
            },
            "downloads": -1,
            "filename": "urlshortening-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "74cf94db36d8f54ebb1b44c6bf6ea32b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9304,
            "upload_time": "2024-09-07T22:40:40",
            "upload_time_iso_8601": "2024-09-07T22:40:40.704886Z",
            "url": "https://files.pythonhosted.org/packages/4e/5f/06fd0baf21d44f7abab2c6ba697e751300471aa76b899299870756d14f51/urlshortening-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0e73b6e6bcb897f46e2a5fbe9058edd169d04b94b0e468b2624d5c834dcf51ad",
                "md5": "d9c410a6a149adfb3c65517de9cff407",
                "sha256": "22b9b9e3a4506dd37dd89f9d2c876fe0824ad20eff54836cb55ec2901883d4d8"
            },
            "downloads": -1,
            "filename": "urlshortening-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d9c410a6a149adfb3c65517de9cff407",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8129,
            "upload_time": "2024-09-07T22:40:42",
            "upload_time_iso_8601": "2024-09-07T22:40:42.202065Z",
            "url": "https://files.pythonhosted.org/packages/0e/73/b6e6bcb897f46e2a5fbe9058edd169d04b94b0e468b2624d5c834dcf51ad/urlshortening-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-07 22:40:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Enkompass",
    "github_project": "django-urlshortening",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "urlshortening"
}
        
Elapsed time: 0.76938s