{"id":21171490,"url":"https://github.com/tebogoyungmercykay/restful_api_implementation_in_php","last_synced_at":"2025-03-14T17:26:02.143Z","repository":{"id":194774707,"uuid":"690613552","full_name":"TebogoYungMercykay/RESTful_API_Implementation_In_PHP","owner":"TebogoYungMercykay","description":"This Implementation serves as a comprehensive guide that empowers developers to understand, interact with, and integrate an Application Programming Interface (API) seamlessly into your applications.","archived":false,"fork":false,"pushed_at":"2023-10-13T20:31:11.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T10:51:16.088Z","etag":null,"topics":["authentication","database-dump","encryption-decryption","get","localhost","php","phpmyadmin-database","post","requests","restful-api","security","singleton"],"latest_commit_sha":null,"homepage":"https://github.com/TebogoYungMercykay/RESTful_API_Implementation_In_DotNet","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TebogoYungMercykay.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":"2023-09-12T14:26:56.000Z","updated_at":"2023-09-18T20:41:06.000Z","dependencies_parsed_at":"2023-10-14T21:01:58.469Z","dependency_job_id":null,"html_url":"https://github.com/TebogoYungMercykay/RESTful_API_Implementation_In_PHP","commit_stats":null,"previous_names":["tebogoyungmercykay/restful_api_implementation_in_php"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRESTful_API_Implementation_In_PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRESTful_API_Implementation_In_PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRESTful_API_Implementation_In_PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TebogoYungMercykay%2FRESTful_API_Implementation_In_PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TebogoYungMercykay","download_url":"https://codeload.github.com/TebogoYungMercykay/RESTful_API_Implementation_In_PHP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243617294,"owners_count":20320048,"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":["authentication","database-dump","encryption-decryption","get","localhost","php","phpmyadmin-database","post","requests","restful-api","security","singleton"],"created_at":"2024-11-20T16:06:31.571Z","updated_at":"2025-03-14T17:26:02.118Z","avatar_url":"https://github.com/TebogoYungMercykay.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Documentation\n\n- This documentation serves as a comprehensive `guide` that empowers developers to `understand`, `interact` with, and `integrate` an `Application Programming Interface` (API) seamlessly into your applications.\n- It includes essential details such as `authentication` methods, available `endpoints`, `request` and `response` formats, error handling, and `usage` examples.\n- This API documentation simplifies the process of `leveraging` external services, fostering efficient and effective software development.\n\n---\n\n- ## SECTION 1\n\n  - `Created By`: Selepe Sello\n  - The `End` Goal is to Have the `same` API Implemented using `.NET 6`.\n  - The Implementation is in this Repository: [RESTful_API_Implementation_In_DotNet](https://github.com/TebogoYungMercykay/RESTful_API_Implementation_In_DotNet.git)\n\n  ---\n\n---\n\n- ## SECTION 2\n\n  ### These are the Default Users initially in the Database:\n\n  - #### `Default User 1`:\n\n    - `Name`: Test\n    - `Surname`: User\n    - `Email`: testuser@tuks.co.za\n    - `Password`: @TestUser#564\n    - `API_key`: a9198b68355f78830054c31a39916b7f\n  - #### `Default User 2`:\n\n    - `Name`: John\n    - `Surname`: Doe\n    - `Email`: johndoe3@gmail.com\n    - `Password`: tEst@us5e#hd\n    - `API_key`: K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\n    ---\n---\n\n- ## SECTION 3\n\n  - All Requests to the `Database` should be Sent via `POST` method for security Purposes.\n  - All `API` Request/Response bodies are in the Form of a `JSON` object.\n  - The JSON Object Must contain the `type` attribute and some more data, this is so that the requests can be `distinguishable` and `handled` accordingly.\n  - The `Database` in Question is a `MySQL` Database, Tool: `phpMyAdmin`.\n  - The the `API_keys` on the `database` for sending `requests` to the API are included in `SECTION 1`.\n  - #### `Note Well:`\n\n    - All `SENSITIVE` data sent to the api like `passwords`, `usernames/emails` and etc will be `encrypted` from the client side first.\n    - Then on the `API`, The Data will be `Decrypted` and `Handled` accordingly.\n  - #### `Example Requests:`\n\n    - ###### `SignUp`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"signup\",\n          \"signup\":{\n            \"name\":\"John\",\n            \"surname\":\"Doe\",\n            \"email\":\"johndoe3@gmail.com\",\n            \"password\":\"tEst@us5e#hd\",\n            \"PassConfirmation\":\"tEst@us5e#hd\",\n            \"account\": \"default\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\"\n        }\n        ```\n    - ###### `Login`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"login\",\n          \"login\":{\n            \"username\":\"johndoe3@gmail.com\",\n            \"password\":\"tEst@us5e#hd\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\"\n        }\n        ```\n    - ###### `Logout`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"logout\",\n          \"logout\":{\n            \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"User Successfully Logged Out!\"\n        }\n        ```\n    - ###### `Preferences`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"preferences\",\n          \"preferences\":{\n            \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\",\n            \"theme\":\"dark\",\n            \"pref\":\"param\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"Preferences Set Successfully!\"\n        }\n        ```\n    - ###### `Delete Account`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"delete_account\",\n          \"delete_account\":{\n            \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\",\n            \"username\":\"johndoe3@gmail.com\",\n            \"password\":\"tEst@us5e#hd\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"Account Deletion Successful!\"\n        }\n        ```\n    - ###### `Change Password`:\n\n      - For this request, A user is not allowed to change their username/\n      - ###### Request by User 2:\n\n        - ###### `When Logged In:`\n\n          ```json\n          {\n            \"type\":\"change_password\",\n            \"change_password\":{\n              \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\",\n              \"new_password\":\"tEst@us5e#hd\"\n            }\n          }\n          ```\n        - ###### `When User is not Logged In:`\n\n          ```json\n          {\n            \"type\":\"change_password\",\n            \"change_password\":{\n              \"username\":\"johndoe3@gmail.com\",\n              \"password\":\"tEst@us5e#hd\",\n              \"new_password\":\"tEerray@5e#hd\"\n            }\n          }\n          ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"Password Changed Successfully!\"\n        }\n        ```\n    - ###### `Generate New ApiKey`:\n\n      - For this request, A user is not allowed to change their username/email\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"generate_apikey\",\n          \"generate_apikey\":{\n            \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": \"API Key Updated Successfully!\"\n        }\n        ```\n    - ###### `Get Data`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"get_data\",\n          \"get_data\":{\n            \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\",\n            \"limit\":4,\n            \"sort\":\"id_trim\",\n            \"order\": \"ASC\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": [\n            {...},\n            {...},\n            {...},\n            {...}\n          ]\n        }\n        ```\n    - ###### `Generate_External_data`:\n\n      - ###### Request by User 2:\n\n        ```json\n        {\n          \"type\":\"Generate_External_data\",\n          \"Generate_External_data\":{\n            \"apikey\":\"K9yW8cGnE3qTfR7xV2sZ6bN1mJ4jL5p\"\n          }\n        }\n        ```\n      - ###### Response form API\n\n        ```json\n        {\n          \"status\": \"success\",\n          \"timestamp\": 1680911562,\n          \"data\": [\n            {...},\n            {...},\n            {...},\n            {...},\n            {...},\n            {...},\n            {...}\n          ]\n        }\n        ```\n    ---\n\n---\n\n- ## SECTION 4\n\n  - ### How the Sign Up and Login Works:\n\n    - A User must have an account to view the Cars for practical 3, and all the other page.\n    - If a `user` doesn't have an account they can only access the `signup`, `login` and `launch` pages.\n    - So the `user` will have to `create an account` and `login`.\n    - When a `user` submits the signup form, the `'required'` from HTML will make sure all fields are filled,\n    - Then `JavaScript` will be loaded, And it will do signup validation on the `client side`.\n    - Thereafter, If `javascript` is done, the form will be sent to `validate-signup.php` via `POST`.\n    - This is to make sure the request is secured, Then `PHP` will do the validation on the `server side`.\n    - Once all the validation is done, the user will be added to the 'users' database table, meaning they will have an account with `Jerman Otto`.\n    - `Sign Up Instructions:`\n      - All Fields SHOULD not be `Empty`\n      - The `NAME` and `SURNAME` fields SHOULD contain only Characters\n      - The `EMAIL` SHOULD contain `@gmail.com` or `@tuks.co.za`, and AT LEAST a Character on the LEFT.\n      - Make sure the EMAIL doesn't contain `Illegal Characters`\n      - Make sure the PASSWORD is at least `8 Characters` long and contains a `Number`, Contains a `Special Character`, `Uppercase` and `Lowercase` letters.\n      - Make sure the PASSWORD doesn't contain Illegal Characters\n      - The PASSWORD and CONFIRM PASSWORD SHOULD `match`\n      - ###### This Is Implemented to make sure the Password is strong and it cannot be guessed or generated easily by Attackers using `Brute Force Attacks` and stuff.\n\n    ---\n  - ### How My Encryption Algorithm Works\n\n    - Generate a `RANDOM` int, SALT value between `[2000000000, 2147483646]`.\n    - Encrypt PASSWORD using the random number as the `salt` with `sha256` and `hash_pbkdf2` method, `hash_pbkdf2(\"sha256\", p, s, i, b)`;\n    - Using 1000 iterations for the hash_pbkdf2 method, and a HASH length of 32 BYTES, So that it can fit well into a column of this `size` =\u003e `VARCHAR(128)`.\n    - Finally i `Concatenate` the `SALT` and `HASH` and the encode the resulting string to base 64, using `base64_encode()`.\n\n    ---\n  - ### API Key\n\n    - The API key is a random string of `length=32`.\n    - It Contains these `AlphaNumeric` Characters: `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`\n    - The Key is then Displayed to the User using a `\u003cp\u003e` tag in every file right after the Heading.\n    ---\n\n---\n\n- ## SECTION 5\n\n  - ### Basic Setup Before Running/Interpreting the Codes\n\n    - Import the `data` table using the datadb database dumb.\n    - Import the `users` table using the usersdb database dumb, **OR ALTERNATIVELY**\n    - Create another table called `users` with the following fields: \"id\", \"name\", \"surname\", \"email\", \"password\", \"API_key\", \"salt\".\n    - The `id` field should be `Automatically` generated, Using `AUTO_INCREMENT=1`\n    - ##### Testing Requirements:\n\n      - At least Have Xampp installed\n      - Copy the souce code to the httdoc directory\n      - Run the `Apache` and `MySQL` server\n      - url:  `\"http://localhost/path/to/hack_api.php\"`\n      - method: `POST` - (HTTP method)\n      - You may use PostMan to Test if the API Works:\n        - Postman Installation/Tutorial:\n          - Windows 10: [YouTube-Link](https://youtu.be/pBo_oClYjjM?feature=shared)\n          - Windows 11: [YouTube-Link](https://youtu.be/pBo_oClYjjM?feature=shared)\n      - You may/may not use the examples in `Section 2`\n    - ##### Some Useful Links:\n\n      - phpMyAdmin Server: http://localhost/phpmyadmin/index.php?route=/\n      - Database: http://localhost/phpmyadmin/index.php?route=/database/structure\u0026db=brands_database\n      - API: http://localhost/link/to/hack_api.php\n\n    ---\n\n---\n\n\u003cp align=\"center\"\u003eThe End, Thank You\u003c/p\u003e\n\n---\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftebogoyungmercykay%2Frestful_api_implementation_in_php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftebogoyungmercykay%2Frestful_api_implementation_in_php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftebogoyungmercykay%2Frestful_api_implementation_in_php/lists"}