{"id":21977931,"url":"https://github.com/farrelad/basic-php-restful-api","last_synced_at":"2026-05-19T04:11:37.099Z","repository":{"id":259039052,"uuid":"876040583","full_name":"FarrelAD/Basic-PHP-RESTful-API","owner":"FarrelAD","description":"Demonstrate a basic RESTful API written in native PHP 🐘","archived":false,"fork":false,"pushed_at":"2025-10-27T06:59:43.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T08:36:30.727Z","etag":null,"topics":["basic","http","http-server","php","php-native","php-restful-api","php-server","request-response","restful-api"],"latest_commit_sha":null,"homepage":"","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/FarrelAD.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-21T09:52:11.000Z","updated_at":"2025-10-27T06:59:46.000Z","dependencies_parsed_at":"2025-10-27T08:25:53.703Z","dependency_job_id":"b1fb6f68-8188-4158-a2df-4d77233551b8","html_url":"https://github.com/FarrelAD/Basic-PHP-RESTful-API","commit_stats":null,"previous_names":["farrelad/basic-php-restful-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FarrelAD/Basic-PHP-RESTful-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrelAD%2FBasic-PHP-RESTful-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrelAD%2FBasic-PHP-RESTful-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrelAD%2FBasic-PHP-RESTful-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrelAD%2FBasic-PHP-RESTful-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FarrelAD","download_url":"https://codeload.github.com/FarrelAD/Basic-PHP-RESTful-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FarrelAD%2FBasic-PHP-RESTful-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33201543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"online","status_checked_at":"2026-05-19T02:00:06.763Z","response_time":58,"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":["basic","http","http-server","php","php-native","php-restful-api","php-server","request-response","restful-api"],"created_at":"2024-11-29T16:17:01.204Z","updated_at":"2026-05-19T04:11:37.089Z","avatar_url":"https://github.com/FarrelAD.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Basic RESTful API in PHP\n\n## Overview\nThis project is a simple RESTful API built in native PHP. It serves as a learning resource for those interested in understanding how to create a basic RESTful API from scratch. The API provides endpoints to manage user data, allowing users to perform CRUD (Create, Read, Update, Delete) operations.\n\n## Features\n\n- Fully implemented in native PHP with minimal dependencies.\n- Basic CRUD operations for user data.\n- Clean and organized code structure.\n- Custom error handling and responses.\n\n## API Endpoints\nHere are the available API endpoints:\n- Get All Users\n    ```bash\n    GET /api/users\n    ```\n    Retrieves a list of all users\n\n- Add New User\n    ```bash\n    POST /api/users\n    ```\n    Adds a new user to the database. Requires name, age, and job in the request body.\n\n- Get User by ID\n    ```bash\n    GET /api/users/:id\n    ```\n    Retrieves user data for a specified user ID.\n\n- Update User Data\n    ```bash\n    PATCH /api/users/:id\n    ```\n    Updates user data for a specified user ID. Requires at least one of the following fields in the request body: **name**, **age**, or **job**.\n\n- Delete User by ID\n    ```bash\n    DELETE /api/users/:id\n    ```\n    Deletes the user with the specified user ID.\n\n## Project Structure\n\nThe main components of the project include:\n- **public**: Contains `index.php` file as entry point for the project\n- **config**: Contains configuration files and environment variables.\n- **src/routes**: Contains route for HTTP request\n- **src/controllers**: Contains logic for handling API requests. Example: `UsersController.php`\n- **src/models**: Contains database interaction logic. Example: `User.php`\n\n## Getting Started\n\nTo get started with this project, follow the steps below.\n\n### Prerequisites\n- PHP 7.4 or higher\n- A web server (e.g., Apache, Nginx, or PHP built in web server)\n- Composer (for dependency management)\n\n### Installation\n1. Clone the repository:\n    ```\n    git clone https://github.com/FarrelAD/Basic-PHP-RESTful-API.git\n    ```\n2. Navigate to the project directory:\n    ```bash\n    cd Basic-PHP-RESTful-API\n    ```\n3. Install the dependencies:\n    ```bash\n    composer install\n    ```\n\n### Configuration\n\n#### Environment file\n\nCreate a **.env** file in the project root directory to store your environment variables. This is essential for configuring database connections and other settings.\n\nExample .env file:\n```env\nDB_HOST=localhost\nDB_USER=root\nDB_PASS=my_password\nDB_NAME=db_php_restful_api\n```\n\n#### Error Log\n\nCreate an **error.log** file in the logs directory to store all error logs that occur when the application runs.\n\n```\n(root)\n├───config\n├───logs\n│   └───error.log       # This is new file to log the error\n├───public\n├───src\n│   ├───controllers\n│   ├───models\n│   └───routes\n└───vendor\n```\n\n\n## Usage\n\nAfter setting up the project, you can start the web server first. You can use Apache HTTPD, NGINX or PHP built in web server.\n\n```bash\ncomposer run dev\n```\n\nAfter that, you can access the API endpoints using a tool like Postman or cURL.Below are some examples of how to use the endpoints:\n\n### Get All Users\n```bash\ncurl -X GET http://localhost:8000/api/users\n```\n\n### Add New User\n```bash\ncurl -X POST http://localhost:8000/api/users -d \"name=John Doe\u0026age=30\u0026job=Developer\"\n```\n\n### Get User By ID\n```bash\ncurl -X GET http://localhost:8000/api/users/1\n\n```\n\n### Update User Data\n```bash\ncurl -X PATCH http://localhost:8000/api/users/1 -d '{\"name\": \"Jane Doe\"}'\n```\n\n### Delete User By ID\n```bash\ncurl -X DELETE http://localhost:8000/api/users/1\n```\n\n## Error Handling\n\n### API Response Code\nThe API includes custom error handling to manage different scenarios, such as:\n\n- 404 Not Found: When a user is not found.\n- 400 Bad Request: When the request body is empty or required data is missing.\n- 500 Internal Server Error: For unexpected errors during processing.\n\nAll responses are returned in JSON format, providing a consistent structure for success and error messages.\n\n### Error Log\nAll server errors are logged to a file located at **logs/error.log**. This log file can be used to monitor your web application when it is live in production, helping to identify and troubleshoot issues effectively.\n\n\n## License\nThis project is open-source and available under the MIT License. Feel free to modify and use it as a learning resource.\n\n## Star History\n\n\u003ca href=\"https://www.star-history.com/#FarrelAD/Basic-PHP-RESTful-API\u0026type=date\u0026legend=top-left\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=FarrelAD/Basic-PHP-RESTful-API\u0026type=date\u0026theme=dark\u0026legend=top-left\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=FarrelAD/Basic-PHP-RESTful-API\u0026type=date\u0026legend=top-left\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=FarrelAD/Basic-PHP-RESTful-API\u0026type=date\u0026legend=top-left\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarrelad%2Fbasic-php-restful-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarrelad%2Fbasic-php-restful-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarrelad%2Fbasic-php-restful-api/lists"}