{"id":20345771,"url":"https://github.com/izzypt/ecommerce-rest-api","last_synced_at":"2026-05-30T18:31:32.965Z","repository":{"id":151595588,"uuid":"595858635","full_name":"izzypt/eCommerce-Rest-API","owner":"izzypt","description":"Process of designin, building, documenting and testing a RESTful API","archived":false,"fork":false,"pushed_at":"2023-02-01T12:53:32.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T15:48:01.522Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izzypt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-02-01T00:21:31.000Z","updated_at":"2023-02-02T12:59:20.000Z","dependencies_parsed_at":"2023-04-18T21:46:29.274Z","dependency_job_id":null,"html_url":"https://github.com/izzypt/eCommerce-Rest-API","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izzypt/eCommerce-Rest-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FeCommerce-Rest-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FeCommerce-Rest-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FeCommerce-Rest-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FeCommerce-Rest-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzypt","download_url":"https://codeload.github.com/izzypt/eCommerce-Rest-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FeCommerce-Rest-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33705207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-14T22:09:43.858Z","updated_at":"2026-05-30T18:31:32.948Z","avatar_url":"https://github.com/izzypt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eCommerce-RESTful-API\nThe goal of this repo is to go through the real world phases of building a RESTful (eCommerce or any other) API.\n\n## Phases\n- Specification\n- Design and implement DataBase\n- Routers/Viewsets and Serializers\n- Testing (end to end  \u0026\u0026 Unit test)\n- Documentation\n\n## #1 Specification\n An API specification provides a broad understanding of how an API behaves and how the API links with other APIs. It explains how the API functions and the results to  expect when using the API.\n \n You can download the specifications file for this project from the link below:\n\n- [Specification-v1.docx](https://github.com/izzypt/eCommerce-RESTful-API/files/10547740/Specification-v1.docx)\n\nAnalyzing the specifications we can extract information to help us design a preliminary table list, a draft of what tables we will need in order for our API to work:\n- We can make a list of what entities/subjects we will need ( things we want to store info about)\n- What fields those entities will need (what things we want to store about those entities)\n\n\u003cdiv align=\"center\"\u003e\n \n### Preliminary Table List\n\n \n| Product              | Product Line         | Category             |\n| ---------------------| ---------------------| ---------------------|       \n| Product name         | Product price        | Category Name        |    \n| Product description  | Product image        |       \n| Product type         | Product SKU          |\n|                      | Product color        |\n|                      | Product size         |\n \n\u003c/div\u003e\n\n### Identifying MultiValued Field\n\nIt's important to try and identify any field which might take more than 1 value and remove it (Multivalued field).\n\nFor example, associated to a product we can have multiple images, so one field might not be enoug...\n\nA possible solution is to add a new field for each image , something like this :\n \n\u003cdiv align=\"center\"\u003e\n \n| Product Line         |\n| ---------------------|    \n| Product price        |  \n| Product image1       |\n| Product image2       | \n| Product image3       | \n| Product image4       | \n| Product SKU          |\n| Product color        |\n| Product size         |\n \n\u003c/div\u003e\n \nBut what if our product only has 1 image (we want to avoid empty cells) or we want to add more than 4 images ?\n\nThe best solution is to create a new table for the product image, something like this :\n \n\u003cdiv align=\"center\"\u003e\n \n| Product Image        |\n| ---------------------|    \n| Image name           |  \n| alternative text     |\n| Image Location       |\n \n\u003c/div\u003e\n \nSo , we actually end up with something like this:\n \n\u003cdiv align=\"center\"\u003e\n \n| Product              | Product Line         | Category             | Product Image        |\n| ---------------------| ---------------------| ---------------------| ---------------------|        \n| Product name         | Product price        | Category Name        | Image name           |   \n| Product description  | Product size         |                      | alternative text     |   \n| Product type         | Product SKU          |                      | Image Location       |\n|                      | Product color        |                      \n|                      |                      |\n \n\u003c/div\u003e\n\nTry to keep those in mind, when designing you tables and field :\n\n\n\u003cdiv align=\"center\"\u003e\n \n ![image](https://user-images.githubusercontent.com/73948790/215820151-714acce0-cde8-4e8a-bd3f-4282ba7c3fbf.png)\n\n \n![image](https://user-images.githubusercontent.com/73948790/215817605-33d37d2a-9fd0-472f-ba53-8b9ecaaef85b.png)\n\n\u003c/div\u003e\n\u003c!-- --\u003e\n\u003cdiv align=\"center\"\u003e\n \n### Table and Field Naming Convention\n\u003c/div\u003e\n\nUltimately, you can do whatever you want in terms of naming tables and fields, but the recommendation is to be consistent across the database and try to make it meaningfull and descriptive.\n\u003cdiv align=\"center\"\u003e\n \n![image](https://user-images.githubusercontent.com/73948790/215856169-1997bea1-f839-458d-aeb5-5a95b5b133c2.png)\n\u003c/div\u003e\n\nSince we will be using Python and Django to build our API, if you want to have a deeper understanding of naming convention and code styling convention in Python/Django you can always check the official docs :\n\n- https://peps.python.org/pep-0008/#naming-conventions\n\n\u003cdiv align=\"center\"\u003e\n \n### Database table relationships\n\u003c/div\u003e\n\nLast but not least , we need to define the relationship between our tables.\n\nIdentifying the connections you’ll need between tables is part of the data modeling and schema design process — that is, the process of figuring out how your data fits together, and how exactly you should configure your tables and their fields.\n\nThe relationships between your tables can be:\n\n- One-to-one\n- One-to-many\n- Many-to-many\n\n![DB_RelationShip](https://user-images.githubusercontent.com/73948790/215863332-dafe55f3-33a8-4abb-8b18-909ff0f7c3ad.png)\n\nIf you want to read more about database table relationship, follow this link : https://www.metabase.com/learn/databases/table-relationships\n\n## #2 Setting up Django\n\nI'am not going to cover step by step the entire process of setting up Django (I already have that on other repos), but I want to touch on some key points, those are :\n\n- Configuring multiple file setting (separate development settings from production settings)\n- Generating a Secret Key\n- Configuring Environment variables\n\n\u003cdiv align=\"center\"\u003e\n\n### -\u003e Configuring multiple settings files\n\n\u003c/div\u003e\n\nBy default, our django project will come with a default \"settings.py\", which \"manage.py\" file will set to the default settings as you can see below: \n\n![image](https://user-images.githubusercontent.com/73948790/215871811-cd10305d-c1da-4e71-97e4-12a81bc8c066.png)\n\nOne way to have multiple settings files and use them interchangeably according to our environment (production or development) is the following:\n\n- Inside our main folder create a settings folder.\n- Move the \"settings.py\" to the settings folder.\n- Since we changed the locations of our \"settings.py\" file, we need to let \"manage.py\" know the new location:\n![image](https://user-images.githubusercontent.com/73948790/215873312-fac9bf45-5b79-4681-a8e1-41e66b6eddd2.png)\n\n- Now, inside our settings folder, we can create 2 new files: one for the development settings and one for production settings. Let's call them \"dev_settings.py\" and \"prod_settings.py\".\n- In those 2 new files , we can import the main settings file configurations and change them to our needs.\n- Once we have done that, we can then, on our \"manage.py\" set the logic to change between those to files, depending on if ```DEBUG=TRUE or DEBUG=False```\n\n![image](https://user-images.githubusercontent.com/73948790/215875541-a099eaf2-2dda-4c48-8e53-3984108a8ff1.png)\n\n\u003cdiv align=\"center\"\u003e\n\n### -\u003e Generating a Secret Key\n\n\u003c/div\u003e\n- Run \n\n``` \npython manage.py shell\n```\n\n- Inside it, run the following commands:\n\n```\n\u003e\u003e\u003e from django.core.management.utils import get_random_secret_key\n\u003e\u003e\u003e new_secret_key = get_random_secret_key\n\u003e\u003e\u003e new_secret_key\n'#r4#$v54nt(k9g*8z-$=v4yexsm2%fevqsz1(+iy(4@^nj^m$5'\n```\n\n- Paste the new key into your \"settings.py\" or your ```.env``` file.\n\n\u003cdiv align=\"center\"\u003e\n\n### -\u003e Configuring Env variables\n\n\u003c/div\u003e\n\n- Create a ```.env``` file in the project.\n\n- pip install python-dotenv\n\n- Load env variables where you need them. Most likely on \"settings.py\" :\n```\nfrom dotenv import load_dotenv\n\nload_dotenv()  # take environment variables from .env.\n\n# Code of your application, which uses environment variables (e.g. from `os.environ` or\n# `os.getenv`) as if they came from the actual environment.\n```\n- Import them by acessing the os.environ :\n\n```\nimport os\n\nSECRET_KEY = os.environ.get(\"SECRET_KEY\")\n```\n\n## Testing our API\n\n- We will use pytest\n\n```\npip install pytest\n```\n- Create a file called \"pytest.ini\" at the root of our project folder. \n- We can customize some pytest behavior using this file. \n- This file contains a number of configuration values that are applied to all test runs for that project.\n- To get a list of the possible options for the \"pytest.ini\" config file you can run the command ``` pytest -h ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fecommerce-rest-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzypt%2Fecommerce-rest-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fecommerce-rest-api/lists"}