A REST API is “an architectural style consisting of a coordinated set of architectural constraints applied to components, connectors, and data elements, within a distributed hypermedia system”. It’s often used to share information using either a JSON or XML format, as seen in this example over at thetvdb.com.
Writing a small API from scratch requires a few things. First we need to figure out how to format the URL, then we have to create a PHP script that posts information (usually from a database) formatted in either XML or JSON. This script needs to accept part of the URL as a parameter, not unlike the traditional use of the $_GET variable. These basic tasks are good to start out with, and should result in a decent first attempt at an API. In followup-articles I’ll write about my experiences with the three topics.
- URL redirection
- Database and $_GET handling
- XML/JSON formatting in PHP