Learn how to develop a complete, RESTful API using plain, object-oriented PHP, MySQL and best practices.
Full API course, including authentication:
‣ https://davehollingworth.net/phpapisy
Please consider supporting my channel:
☕ https://ko-fi.com/davehollingworth
In this video you'll learn how to:
• create RESTful URLs
• list, show, create, update and delete database records using an API
• organise your PHP code
• use controllers and table gateways
• return relevant HTTP status codes
• validate data in an API
• decode and encode requests and responses as JSON
Code shown in the video:
‣ https://github.com/daveh/php-rest-api
Relevant documentation:
‣ https://curl.se/
‣ https://www.postman.com/
‣ https://httpie.io/
‣ https://www.php.net/manual/en/functio...
‣ https://www.php.net/manual/en/pdo.set...
‣ https://www.php.net/manual/en/class.e...
00:00 Introduction
00:18 API client
00:31 Front controller
01:38 RESTful endpoints
02:03 URL rewriting
03:03 HTTPie usage
03:28 Routing
03:59 404 response
04:23 Collection and resource URLs
05:19 Controller class
06:27 Class autoloading
08:19 Process the request
09:06 Collection requests
09:55 JSON Content-type
10:56 Create the database
11:53 Connect to the DB
14:08 Exception handling
16:44 Table gateway class
17:42 List all records
19:52 Encode JSON values
21:35 Insert a record
21:55 Get request data
27:04 201 response
28:00 Error handling
30:00 Data validation
31:46 422 response
32:28 405 response
33:36 Resource requests
34:43 Get a resource
35:59 404 response
37:02 Update a resource
40:03 Conditional validation
41:12 Delete a resource
43:12 Summary
#PHP #MySQL #REST #API