Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.69 KB

README.md

File metadata and controls

41 lines (27 loc) · 1.69 KB

#PHP REST API Template

This sample code can be used to create a REST API in PHP for educational purposes, not production use. The file structure and architecture is already provided, including the key features needed for any API. Add the controller and model files and you should be ready to go.

Some of the key features:

  • MVC Framework
  • REST architectural style
  • Request handler
  • Selectable response structure - JSON or XML, using &format URL parameter
  • Enable/disable authentication, using public-private key encryption
  • Debugging mode for request and response
  • Exception handling - displaying end logging errors
  • Automatic metadata/help page
  • Sample Users controller with CRUD database operations
  • Automatic class loading for Models/Views/Controllers

The automatic metadata page is available when hitting the API's base URL, for example http://localhost:7080/REST_API_Framework

SAMPLE REQUESTS

GET USERS

http://localhost:7080/REST_API_Framework/users?format=json&public_key=abc&public_hash=a5d6ae8ac2d017771c075f887064d38e81169f8021be8ba473babcebb7459376

<public_key>abc</public_key><public_hash>a5d6ae8ac2d017771c075f887064d38e81169f8021be8ba473babcebb7459376</public_hash>

{"authentication":{"public_key":"abc","public_hash":"a5d6ae8ac2d017771c075f887064d38e81169f8021be8ba473babcebb7459376"}}

GET USER

http://localhost:7080/REST_API_Framework/users/1?format=json

INSERT USER

{"user":{"first_name":"Adrian","last_name":"Smith", "email":"[email protected]"}}