{"id":18880706,"url":"https://github.com/nant1ng/rest-api_ecommerce","last_synced_at":"2025-06-16T10:40:18.046Z","repository":{"id":157643692,"uuid":"349781926","full_name":"Nant1ng/REST-API_Ecommerce","owner":"Nant1ng","description":"This is a school assignment. The assignment was about creating a REST API for E-commerce. I have only used plain PHP and no frameworks. The RESTful API will only return results in JSON and I have used CRUD principles.","archived":false,"fork":false,"pushed_at":"2021-04-11T21:02:01.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-31T03:22:23.222Z","etag":null,"topics":["php","rest-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/Nant1ng.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":"2021-03-20T16:44:53.000Z","updated_at":"2023-02-07T19:32:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"810ff995-3388-4c59-a8c0-f90ba6358fff","html_url":"https://github.com/Nant1ng/REST-API_Ecommerce","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/Nant1ng%2FREST-API_Ecommerce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nant1ng%2FREST-API_Ecommerce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nant1ng%2FREST-API_Ecommerce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nant1ng%2FREST-API_Ecommerce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nant1ng","download_url":"https://codeload.github.com/Nant1ng/REST-API_Ecommerce/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239847720,"owners_count":19707015,"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":["php","rest-api"],"created_at":"2024-11-08T06:45:37.976Z","updated_at":"2025-02-20T13:40:33.468Z","avatar_url":"https://github.com/Nant1ng.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REST-API_E-commerce \n\n- [Description](#description)\n- [Endpoints](#endpoints)\n- [Before using the code](#Before-using-the-code)\n- [How to](#how-to)\n\n---\n\n## Description\n\n#### This is a school assignment. The assignment was about creating a REST API for E-commerce. I have only used plain PHP and no frameworks. The RESTful API will only return results in JSON and I have used CRUD principles.\n\n---\n\n## Endpoints\n\n### Users \n\n---\n\n#### POST - Create user\n[![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/)\n\u003ehttp://localhost/REST_API/V1/users/Create.php\n\n### GET - Read all users \n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/)\n\u003ehttp://localhost/REST_API/V1/users/ReadAll.php \n\u003cbr\u003e\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n\n---\n\n### Sessions\n\n---\n\n#### POST - Log in\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/)\n\n\u003ehttp://localhost/REST_API/V1/sessions.php\n\n#### PATCH - Refresh accesstoken\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/)\n\n\u003ehttp://localhost/REST_API/V1/sessions.php?sessionid=(Your session id)\u003c/br\u003e\nUse the same session id you got when logged in.\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n\n#### DELETE - Log out\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/sessions.php?sessionid=(Your session id)\u003c/br\u003e\nUse the same session id you got when logged in. \nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n### Products\n---\n\n#### GET - Read products\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/products/ReadAll.php?(Page number)\u003c/br\u003e\nOnly 2 products per page, just to show that page nation works. \u003c/br\u003e Pagenumber can be 1 or 2 and so on.\n---\n\n#### GET - Read single product\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/products/Read.php?productid=(Product ID)\u003c/br\u003e\nProduct ID need to be an existing id.\n---\n\n#### POST - Create product\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/products/Create.php \u003cbr\u003e\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n#### DELETE - Delete product\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/products/Delete.php?productid=(Product ID)\u003c/br\u003e\nProduct ID need to be an existing id. \nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n#### PATCH - Update product\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/products/Update.php?productid=(Product ID)\u003c/br\u003e\nProduct ID need to be an existing id.\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n### Cart\n\n---\n\n#### POST - Add product to cart\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/)\n\n\u003ehttp://localhost/REST_API/V1/carts/Create.php?productid=(Product ID)\u003c/br\u003e\nProduct ID need to be an existing id.\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n#### DELETE - Delete product from cart\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/carts/Delete.php?productid=(Product ID)\u003c/br\u003e\nProduct ID need to be an existing id.\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n#### GET - Read cart \n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/carts/Read.php \u003cbr\u003e \nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n#### POST - Checkout cart\n[![made-with-python](https://img.shields.io/badge/Admin-darkred)](https://shields.io/) [![made-with-python](https://img.shields.io/badge/User-red)](https://shields.io/) \n\n\u003ehttp://localhost/REST_API/V1/carts/Checkout.php \u003cbr\u003e\nYou need to put the accesstoken provided in header: Authorization = accesstoken.\n---\n\n## Before using the code \n\n\u003cdetails\u003e\n\u003csummary\u003eYou need to follow this steps\u003c/summary\u003e\n\n\u003e You need these programs for the API to work:\n- Xampp or Mamp - Local database connection.\n- Visual Studio Code or other code editor - To open or edit the code.\n- Postman - To send requests.\n\n\u003e Download and use the API:\n- Step 1 - Clone this repository.\n- Step 2 - Start Xampp or Mamp and open phpMyAdmin.\n- Step 3 - Use the SQL script included in the project to create database with the name rest_api.\n- Step 4 - Open Postman and start making requests!.\n\n\u003c/details\u003e\n\n---\n\n## How to \n\n\u003cdetails\u003e\n\u003csummary\u003eCreate users, sessions or products?\u003c/summary\u003e\n\n### Create Users: \nYou need to have Content-Type: application/json in header\n```html\n{\n    \"fullname\":\"Your Name\",\n    \"email\":\"email@gmail.com\",\n    \"username\":\"Username\",\n    \"password\":\"Password\"\n}\n```\n\n---\n\n### Create Sessions: \nYou need to have Content-Type: application/json in header\n```html\n{\n    \"username\":\"Username\",\n    \"password\":\"Password\"\n}\n```\n\n---\n\n### Create Products: \nYou need to have Content-Type: application/json in header\n```html\n{\n    \"product_title\":\"Product Title\",\n    \"description\":\"Product Description\",\n    \"price\":\"Product Price\",\n    \"stock\":\"Y\",\n    \"img_url\":\"img-url\"\n}\n```\n\n---\n\n\u003c/details\u003e\n\n---\n\n## Success Response Examples\n\n\n\n\u003cdetails\u003e\n\u003csummary\u003eShow Examples\u003c/summary\u003e\n\n### User created: \n``` html \n{\n    \"statusCode\": 201,\n    \"success\": true,\n    \"message\": [\n        \"User created, welcome Your Name\"\n    ],\n    \"data\": {\n        \"user_id\": \"1\",\n        \"fullname\": \"Your Name\",\n        \"email\": \"email@gmail.com\",\n        \"username\": \"Username\"\n    }\n}\n```\n\n---\n\n### Session created: \n``` html \n{\n    \"statusCode\": 201,\n    \"success\": true,\n    \"message\": [\n        \"Logged in\"\n    ],\n    \"data\": {\n        \"session_id\": 1,\n        \"access_token\": \"MzM2MzQ5MDk2MDYwNmFmYTBkMDBjMTY2NDRjNmRiNWM0MTQxOThkZDg1NjJkNWY4MTYxODE2OTEwNA==\",\n        \"access_token_expires_in\": 3600,\n        \"refresh_token\": \"MmU2ZTk1YmRiNDYyZjc2YWUyNzc0OWM3MTcwYjBkMzQ5MDkzNTM5YTIwNGZmMmIyMTYxODE2OTEwNA==\",\n        \"refresh_token_expires_in\": 1209600\n    }\n}\n```\n\n---\n\n### Product created: \n``` html \n\n    \"statusCode\": 201,\n    \"success\": true,\n    \"message\": [\n        \"Product Created\"\n    ],\n    \"data\": {\n        \"rows_returned\": 1,\n        \"product\": [\n            {\n                \"id\": 1,\n                \"product_title\":\"Product Title\",\n                \"description\":\"Product Description\",\n                \"price\":\"Product Price\",\n                \"stock\":\"Y\",\n                \"img_url\":\"img-url\"\n            }\n        ]\n    }\n}\n```\n\n\u003c/details\u003e\n\n---\n\n## Error Respons Examples\n\n\u003cdetails\u003e\n\u003csummary\u003eShow Examples\u003c/summary\u003e\n\n### Creating User Error:\n``` html\n{\n    \"statusCode\": 409,\n    \"success\": false,\n    \"message\": [\n        \"Username or Email already exists\"\n    ],\n    \"data\": null\n}\n```\n\n--- \n\n### Creating Sessions Error:\n``` html\n{\n    \"statusCode\": 400,\n    \"success\": false,\n    \"message\": [\n        \"Username cannot be blank\",\n        \"Password cannot be blank\"\n    ],\n    \"data\": null\n}\n``` \n\n---\n\n### Creating Product Error:\n``` html\n{\n    \"statusCode\": 400,\n    \"success\": false,\n    \"message\": [\n        \"Product Price Error\"\n    ],\n    \"data\": null\n}\n``` \n\u003c/details\u003e\n\n---\n\n\u003cbr\u003e\n\n[Back To The Top](#REST-API_E-commerce)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnant1ng%2Frest-api_ecommerce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnant1ng%2Frest-api_ecommerce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnant1ng%2Frest-api_ecommerce/lists"}