{"id":16419644,"url":"https://github.com/foo290/django-rest-api","last_synced_at":"2025-02-24T13:41:18.569Z","repository":{"id":123397013,"uuid":"290977441","full_name":"foo290/Django-REST-API","owner":"foo290","description":"A simple and clean REST API for Django.","archived":false,"fork":false,"pushed_at":"2020-09-30T07:13:50.000Z","size":950,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-06T21:48:07.132Z","etag":null,"topics":["api","django","django-api","django-framework","django-rest-framework","djangorestframework","python","restful-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foo290.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-08-28T07:13:34.000Z","updated_at":"2024-08-02T17:56:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"c04ae0e1-c28a-42bc-abb9-3e85c59ac647","html_url":"https://github.com/foo290/Django-REST-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/foo290%2FDjango-REST-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo290%2FDjango-REST-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo290%2FDjango-REST-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo290%2FDjango-REST-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foo290","download_url":"https://codeload.github.com/foo290/Django-REST-API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240491570,"owners_count":19809977,"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":["api","django","django-api","django-framework","django-rest-framework","djangorestframework","python","restful-api"],"created_at":"2024-10-11T07:25:25.641Z","updated_at":"2025-02-24T13:41:18.541Z","avatar_url":"https://github.com/foo290.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003ch1 align='center'\u003eDJANGO-REST-API\u003c/h1\u003e\n\n\n\u003cp align=\"center\" \u003e\n\u003cimg  height=\"200\" src='https://github.com/foo290/Django-REST-API/blob/master/readme_imgs/django.png?raw=true' alt='An image was supposed to be here . . .'\u003e\n\u003c/p\u003e\n\n# Output\n\n```\n$ curl http://127.0.0.1:8000/api.domain/users/1/\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n100  1329  100  1329    0     0  41531      0 --:--:-- --:--:-- --:--:-- 42870{\n    \"status\": 200,\n    \"id\": \"1\",\n    \"details\": {\n        \"last_login\": \"2020-09-19T08:09:18.895Z\",\n        \"username\": \"ns290\",\n        \"first_name\": \"Nitin\",\n        \"last_name\": \"Sharma\",\n        \"email\": \"ns@gmail.com\",\n        \"is_active\": true,\n        \"date_joined\": \"2020-09-13T05:57:07Z\",\n        \"groups\": [],\n        \"user_permissions\": [],\n\t}\n}\n```\n\n## Output after adding profile and post models to USER_RELATED_MODEL\n\n```\n$ curl http://127.0.0.1:8000/api.domain/users/1/\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n100  1329  100  1329    0     0  41531      0 --:--:-- --:--:-- --:--:-- 42870{\n    \"status\": \"Success\",\n    \"id\": \"1\",\n    \"details\": {\n        \"last_login\": \"2020-09-19T08:09:18.895Z\",\n        \"username\": \"ns290\",\n        \"first_name\": \"\",\n        \"last_name\": \"\",\n        \"email\": \"ns@gmail.com\",\n        \"is_active\": true,\n        \"is_staff\": true,\n        \"date_joined\": \"2020-09-13T05:57:07Z\",\n        \"groups\": [],\n        \"user_permissions\": [],\n        \"profile\": {\n            \"user\": 1,\n            \"img\": \"default_pfp.jpg\",\n            \"bio\": 'Keep it logically awesome! 😃',\n            \"city\": null,\n            \"country\": 'India',\n            \"company\": null,\n            \"github\": 'https://github.com/foo290',\n            \"twitter\": 'https://twitter.com/_foo290',\n            \"instagram\": \"https://instagram.com/_iamnitinsharma\",\n            \"website\": 'https://foo290.github.io.com'\n        },\n        \"post\": [\n            {\n                \"id\": 1,\n                \"title\": \"post 1\",\n                \"author\": 1\n            },\n            {\n                \"id\": 2,\n                \"title\": \"post 2\",\n                \"author\": 1\n            },\n            {\n                \"id\": 3,\n                \"title\": \"post 3\",\n                \"author\": 1\n            }\n        ]\n    }\n}\n\n```\n\n\n# Intro\nDjango-REST-API is an app which lets you make get request to the database using Django's inbuilt ORMs and returns data in JSON\n\n## Installation\nclone the repo and run the following command where \"dist\" dir is :\u003cbr\u003e\nNOTE : Don't forget to activate virtual environment if you have one.\n\n```\npython -m pip install dist/Django-REST-API-1.0.tar.gz\n```\n\n\n## Quick start\nThe steps to getting started is very simple. Like any other app, this can be installed easily by adding \"api_response\" in your installed apps like:\n\n### Step 1 :-\nAdd \"api_response\" to your INSTALLED_APPS setting like this:\n```\n    INSTALLED_APPS = [\n        ...\n        \"api_response\",\n    ]\n```\n### Step 2 :-\nInclude the \"api_response\" URLconf in your project urls.py like this:\n```\nurlpatterns = [\n\t...\n\tpath('api.response/', include('api_response.urls')),\t\n\n]\n```\n\n```\nNote : change the url pattern ('api.response/') to anything you like...\n```\n\n### Step 3 :-\nSpecify the apps on which you want to enable the api in \u003cb\u003esettings.py\u003c/b\u003e as :\n\n```\nAPI_ENABLED_APPS = {\n    'App name': 'Model name'\n}\n\nA dict that contains your 'App name' as key and 'Model name' as its values.\n```\n### Important : If you have more than one model in you app, you can simply pass them in a list or tuple as :\n\n```\nAPI_ENABLED_APPS = {\n    'App name': ['Model 1 name', 'model 2 name', ... ]\n}\n\nA dict that contains your 'App name' as key and list of 'Model name' as its values.\n```\nNote 'Model name' is the class name you make in your App.models file by inheriting models.Model and App name is simply the name of your app.\n\n#### At this point, your api is ready to use\n Start the development server and visit http://127.0.0.1:8000/api.yourDomain/\n\n you will see a welcome message at api endpoint as :\n```\n{\n    \"WELCOME\": \"This is the api endpoint.\",\n    \"suggested\": \"Start making request on API_URLS that you've specified\",\n}\n```\n### Note : Your URLs are namespaced as 'app_name/model_name/' so if you have an app named 'blog' and model named 'Post', the url will be:\n```\nhttp://127.0.0.1:8000/api.response/blog/post/\n```\nThese API urls can be customized and you can specify your own (multiple) url pattern for your app as described in Advance section below.\n\nNote : At the App's endpoints like ```http://127.0.0.1:8000/api.response/blog/post/``` , only 10 results are shown by default to prevent server from overloading by unwanted computation. This behaviour can be overridden by specifying a variable named ```ENDPOINT_RESPONSE_LENGTH``` in \u003cb\u003esettings.py\u003c/b\u003e . Set this variable to desired number of results you want or set it to \"all\" to get the full results by default.\n\n# Advance\n\n## Customize your api URL patterns\nBy default the urls are namespaced by \"app_name/model_name/\" but you can specify your own url pattern and get more control over passing arguments in URLs by configuring \u003cb\u003esettings.py\u003c/b\u003e as :\n\n```\nAPI_URLS = {\n    'Model name 1': [\n\t\t'pattern 1',\n\t\t'pattern 2',\n\t\t...\n\t],\n\t'Model name 2': [\n\t\t'pattern 1',\n\t\t...\n\t]\n}\n\nA dict containing 'Model name' as key and 'url patterns' (may be multiple) as values.\nFor Ex. :-\n\nAPI_URLS = {\n    'product': [\n        'products/\u003cint:id\u003e/',\n\t'products/\u003cstr:name\u003e/'\n\t\t...\n    ]\n}\n```\n\n### ATTENTION : The arguments names passed in url pattern must be same as fields specified in model.\nfor ex :- \u003cbr\u003e\nmodels.py :\n```\nfrom django.db import models\n\nclass Product(models.Model):\n    name = models.CharField(max_length = 100)\n    price = models.FloatField()\n\t\n\t...\n```\nIn the example above, if I want to make a url pattern which gets the products for a specific price or name, the pattern's argument names will be 'name' and 'price'. Ex :\n```\nAPI_URLS = {\n    'product': [\n        'products/\u003cstr:name\u003e/',\t--\u003e 'name' as argument\n\t\t'products/\u003cint:price\u003e/'\t--\u003e 'price' as argument\n\t\t...\n    ]\n}\n```\n\u003cb\u003eNote:\u003c/b\u003e If you specify URL for an app in API_URLS, you are fully responsible for the pattern specified.\n\nOn every start of dev server, the url patterns will be printed on console to confirm it is made as specified like :\n\n```\npython manage.py runserver\n\n\nPerforming system checks...\n\nAPI_URL_patterns --\u003e [\u003cURLPattern 'products/'\u003e, \u003cURLPattern 'blog/'\u003e, \u003cURLPattern 'users/\u003cslug:userid\u003e/'\u003e, \u003cURLPattern ''\u003e, \u003cURLPattern 'users/'\u003e]\n\nStarting development server at http://127.0.0.1:8000/\nQuit the server with CTRL-BREAK.\n```\n\n## Block default api URL:\nAs urls for api are made by default as soon as the apps is added in API_ENABLED_APPS, you can block urls for apps by typing \"block\" inplace of pattern and default urls will be removed for that model.\n\n### This does not block your url to access the page.\n\nFor ex:\n```\nAPI_URLS = {\n    'product': [\n        'block'\n    ]\n}\n```\nYou can see if the URL is blocked or not when you run dev server as :\n\n```\npython manage.py runserver\n\n...\nPerforming system checks...\n\nAPI URL blocked for  --\u003e \"product\", by URL_PATTERN_BLOCKER : \"block\"\n\nStarting development server at http://127.0.0.1:8000/\nQuit the server with CTRL-BREAK.\n```\n\n## Getting User data :\nUser model may have relations with other models in apps in your projects (like users have profile or posts of blogs) either by ForeignKey or One-to-One fields. To get these included in user api response, simple specify USER_RELATED_MODELS with model names you want to include in \u003cb\u003esettings.py\u003c/b\u003e as\n\n```\nUSER_RELATED_MODELS = [\n    'profile',\n\t'post', \n]\n\nA list containing model names which have some relations with User by ForeignKey or One-to-one relation.\n```\n\n## Accessing user's api URL\nYou can get user details either by user id or username as they are unique identifiers by visiting.\n\n```\nhttp://127.0.0.1:8000/api.response/users/id/\n\t\t\tOR\nhttp://127.0.0.1:8000/api.response/users/username/\n```\n\n#### To uninstall, run the following command:\n```\npython -m pip uninstall Django-REST-API\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo290%2Fdjango-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoo290%2Fdjango-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo290%2Fdjango-rest-api/lists"}