{"id":20551593,"url":"https://github.com/do-community/url-shortener-api","last_synced_at":"2025-04-14T11:30:56.132Z","repository":{"id":90798465,"uuid":"305512467","full_name":"do-community/url-shortener-api","owner":"do-community","description":"An API for creating quick links","archived":false,"fork":false,"pushed_at":"2021-05-24T21:32:40.000Z","size":43,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T00:44:03.067Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/do-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-19T21:03:12.000Z","updated_at":"2022-02-11T16:18:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"29750740-2294-419b-88d2-ed6214367a58","html_url":"https://github.com/do-community/url-shortener-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/do-community%2Furl-shortener-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/do-community%2Furl-shortener-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/do-community%2Furl-shortener-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/do-community%2Furl-shortener-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/do-community","download_url":"https://codeload.github.com/do-community/url-shortener-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248871693,"owners_count":21175273,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T02:32:22.949Z","updated_at":"2025-04-14T11:30:56.104Z","avatar_url":"https://github.com/do-community.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# url-shortener-api\nAn API for creating quick redirect links\n\n## Modes\nThere are two modes the API can run in. When the environment variable `REDIRECT`\nis set to `True` then any short link sent to the API root will return a 302 redirect.\nHowever, if `REDIRECT` is set to `False`, the API will merely return a JSON respone\nwith the location of where the redirect is set.\n\nDefault is set to `True`.\n\n## How to Deploy to DigitalOcean's App Platform\n\n* This app will need a database, so either stand up your own or use an App Platform dev db.\n* The run command should be `gunicorn --worker-tmp-dir /dev/shm url_shortener.wsgi`\n* Env Vars\n    * `DJANGO_ALLOWED_HOSTS` - Set this to your custom domain or `${APP_DOMAIN}` to get the default app domain from DigitalOcean\n    * `DATABASE_URL` -  The database connection URL. If using App Platform dev db set to `${\u003cNAME_OF_DB\u003e.DATABASE_URL}` where `\u003cNAME_OF_DB\u003e` is the name you specify for the db at creation\n    * `REDIRECT` - Set to `False` if you want the API to return where the redirect is pointed instead of actually performing the redirect\n    * `APP_PLAT_ROUTE` - If you run this app under a subfolder, ex: my.api.example/api then you'll need to specify what subfolder it's running under. Format should be `/route` with a leading an no trailing slash\n    * `ALLOW_OPEN_ACCESS` - Set to `True` if you want to allow open access to the POST method to add redirects. \n* Once deployed access the console and run `python manage.py migrate` to perform the initial migrations\n* After performing the initial migrations run `python manage.py createsuperuser` in the console and follow the prompt to create a super user\n\n## API Spec\nA full Open API Spec can be found at `/docs/` in Swagger format.\n\nAll examples are using [`httpie`](https://httpie.org/). If you haven't checked \nit out you should.\n\nBelow are all of the public endpoints currently available.\n\n**Note:** - All API methods end with a `/`. If you attempt to call an API method\nwithout this you will receive a 404.\n\n\n### POST `/login/`\nRetrieve a users API token\n\n*Parameters*\n\n* `username` - Your username\n* `password` - Your Password\n\n*Example*\n\n`http POST https://example.api/login/ username=user password=pass`\n\n*Returns*\n\n```\n{\n    \"token\": \"YOUR_API_TOKEN\"\n}\n```\n\n### GET `/\u003cYOUR_SHORT_LINK\u003e`\n\n#### With `REDIRECT` set to `True`\n\nGet either a 302 redirect or a 404.\n\n*Example*\n`http https://example.api/\u003cYOUR_SHORT_LINK\u003e`\n\n#### With `REDIRECT` set to `False`\nGet a JSON response with the location of your redirect\n\n*Example*\n`http https://example.api/\u003cYOUR_SHORT_LINK\u003e`\n```json\n{\n    \"redirect\": \"https://mason.dev\"\n}\n```\n\n### GET `/manage/` - **Auth Required**\nList all the redirects available\n\n*Example*\n\n`http https://example.api/manage/ 'Authorization: Token '$TOKEN` \n\n*Returns 200*\n```json\n[\n    {\n        \"id\": 2,\n        \"short_link\": \"do\",\n        \"url\": \"https://digitalocean.com\",\n        \"visit_count\": 1\n    }\n    ...\n]\n\n```\n\n\n\n### POST `/manage/` - **Auth Required**\nAdd an URL Redirect.\n\n*Parameters*\n\n* `short_link` - The short link you wish to visit to be redirected to another URL\n* `url` - The URL to redirect to\n\n*Example*\n\n`http POST https://example.api/manage/ 'Authorization: Token '$TOKEN short_link=mason url=\"https://mason.dev\"`\n\n*Returns 200*\n```json\n{\n    \"message\": \"Redirect successfully added\"\n}\n```\n\n*Returns 422*\n```\n{\n    \"message\": {\n        \"short_link\": [\n            \"URL Redirect with this short link already exists.\"\n        ],\n        \"url\": [\n            \"This field is required.\"\n        ]\n    }\n}\n```\n\n### PUT `/manage/` - **Auth Required**\nUpdate an URL Redirect.\n\n*Parameters*\n\n* `short_link` - The short link you wish to visit to be redirected to another URL. This is the key\n* `url` - The URL to redirect to \n\n*Example*\n\n`http PUT https://example.api/manage/ 'Authorization: Token '$TOKEN short_link=mason url=\"https://masonegger.com\"`\n\n*Returns*\n```json\n{\n    \"message\": \"Redirect successfully updated\"\n}\n```\n\n*Returns 422*\n```\n{\n    \"message\": {\n        \"url\": [\n            \"This field is required.\"\n        ]\n    }\n}\n```\n\n### DELETE `/manage/\u003cstr:short_link\u003e` - **Auth Required**\nDelete an URL Redirect.\n\n*URI Parameters*\n\n* `short_link` - The short link to delte\n\n*Example*\n\n`http DELETE http://example.api/manage/\u003cSHORT_LINK\u003e/ 'Authorization: Token '$TOKEN`\n\n*Returns 200*\n```json\n{\n    \"message\": \"Redirect successfully deleted\"\n}\n```\n\n*Returns 404*\n```json\n{\n    \"detail\": \"Not found.\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdo-community%2Furl-shortener-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdo-community%2Furl-shortener-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdo-community%2Furl-shortener-api/lists"}