Course Overview
An API is a way for a program to interact with another program. By using third-party APIs from your code, you can utilise functionality developed elsewhere. By creating an API to access your own data, other programs can take advantage of your services in a secure and easy fashion.
Learn how to Use and Create Secure and Scalable APIs in PHP in this Comprehensive Course.
Understand how APIs work
Learn how to use an API from PHP
Understand how HTTP requests and responses work
Understand what REST and RESTful APIs are
Create a RESTful API from scratch, using plain PHP and MySQL
Understand how API authentication works
Add API key authentication to your API
Understand how JSON Web Tokens (JWTs) work
Add JWT access token authentication to your API
The essential skills required to use and develop APIs with PHP.
Unless you create every component of your application from scratch, your code will need to interact with external services - for example a payment gateway, or currency data. To use such services, you need to consume their APIs. On this course you'll learn how to do this from PHP, and also how to create an API so that external programs can interact with your application.
Content and Overview
This course is designed for the PHP developer who wants to learn in depth how to use APIs from their code. I designed the course to be easily understood by PHP developers who have no previous experience of using APIs, and who want to develop full, secure APIs quickly and easily. Learning the techniques on this course will enable you to create APIs that are secure, robust and that comply with industry standards.
Suitable for all PHP developers, you'll start by learning the basics of how APIs work.
You'll learn various techniques for consuming APIs from PHP, along with their advantages and disadvantages.
We'll build a full API from scratch, with each concept explained in detail at every stage.
You'll learn what REST and what RESTful APIs are, why we use them, and how to make your API RESTful.
Throughout the course, we'll build code that you can reuse in all your projects.
All the source code developed in the lectures is available to download.
All the time we'll adhere to industry standards and best practices.
Each section has short, self-contained lectures that you can go back to reinforce specific concepts if you need to.
When you complete the course you'll be able to use APIs in your PHP applications to leverage third-party components and services. You'll also be able to create your own API, using various authentication techniques depending on the type of API you want to create.
Complete with all the code shown in the lectures, you'll be able to work alongside the instructor and will receive a verifiable certificate of completion upon finishing the course.
Also, at all times throughout the course you have access to the instructor in the Q&A section to ask for help with any topic related to the course.
Enrol now and become a master of APIs in PHP!
FAQ
FAQ area empty
Course curriculum
Chương 1 Introduction: how to use the course and software installation 3 bài · 4 phút
Chương 2 API basics: what APIs are and how to use them 5 bài · 15 phút
-
What is an API? 3:57
- Make an API call: access an API from PHP Học thử 2:56
- Decode API results: reading JSON in PHP Học thử 3:59
-
Use API data in a web application 4:12
- API basics Học thử
Chương 3 HTTP basics: requests, responses and using cURL 9 bài · 31 phút
- Use cURL instead of file_get_contents to make an API request Học thử 5:01
-
Response codes: get the HTTP status code 5:08
-
Request headers: add meta data about the request 3:48
-
Response headers: read meta data about the response 2:55
-
Get all individual response headers in an array 3:54
-
Use an API that requires a specific request header 3:24
-
Request method: change the method to get a different result with the same URL 3:43
-
Request body: add a payload to send data along with the request 3:32
-
HTTP fundamentals
Chương 4 REST and RESTful APIs: using them from PHP 4 bài · 18 phút
-
REST and RESTful APIs: what are they? 3:40
-
Access a RESTful API in PHP with cURL 3:51
-
Use the Guzzle HTTP client for object-oriented API code 5:06
-
Use an SDK: compare the Stripe API to its SDK 5:40
Chương 5 Create a RESTful API: build a framework for serving the API 9 bài · 37 phút
-
Start writing the API: enable URL rewriting 3:30
-
The front controller: get the resource, ID and the request method 4:18
-
Use a client for API development: cURL, Postman or HTTPie 3:41
-
Set the HTTP status code: best practices 4:22
-
Add a controller class to decide the response 4:43
-
Use Composer's autoloader to load classes automatically 2:55
-
Make debugging easier: add type declarations and enable strict type checking 3:21
-
Always return JSON: add a generic exception handler and JSON Content-Type header 5:35
-
Send a 405 status code and Allow header for invalid request methods 4:41
Chương 6 Create a RESTful API: create a database and retrieve data from it 10 bài · 31 phút
-
Create a new database and a database user to access it 2:10
-
Create a table to store resource data 1:33
-
Connect to the database from PHP: add a Database class 4:38
-
Move the database connection data to a separate .env file 4:07
-
Create a table data gateway class for the resource table 3:38
-
Show a list of all records 3:17
-
Configure PDO to prevent numeric values from being converted to strings 2:33
-
Convert database booleans to boolean literals in the JSON 2:38
-
Show an individual record 2:55
-
Respond with 404 if the resource with the specified ID is not found 3:57
Chương 7 Create a RESTful API: create, update and delete individual resources 8 bài · 34 phút
-
Get the data from the request as JSON 5:33
-
Insert a record into the database and respond with a 201 status code 5:05
-
Add a generic error handler to output warnings as JSON 2:52
-
Validate the data and respond with a 422 status code if invalid 4:36
-
Conditionally validate the data when updating an existing record 3:17
-
Get the data from the request for updating an existing record 4:50
-
Update the record in the database and return a 200 status code 5:39
-
Delete the record in the database and return a 200 status code 2:24
Chương 8 API key authentication 12 bài · 38 phút
-
Create a table to store user account data 3:40
-
Add a register page to insert a new user record and generate a new API key 6:10
-
Send the API key with the request: query string or request header 3:04
-
Check the API key is present in the request and return 400 if not 1:43
-
Create a table data gateway class for the user table 2:29
-
Authenticate the API key and return a 401 status code if invalid 2:16
-
Refactor the front controller to a bootstrap file and Auth class 4:45
-
Add a foreign key relationship to link task records to user records 2:10
-
Retrieve the ID of the authenticated user when authenticating 2:24
-
Restrict the tasks index endpoint to only show the authenticated user's tasks 2:29
-
Restrict the rest of the task endpoints to the authenticated user's tasks 4:31
-
Cache the database connection to avoid multiple connections in the same request 2:03
Chương 9 An introduction to authentication using access tokens 8 bài · 29 phút
-
An introduction to authentication using access tokens 2:27
-
Create the login script and return 400 if the username and password are missing 3:18
-
Select the user record based on the username in the request 2:51
-
Check the username and password and return a 401 status code if invalid 2:23
-
Generate an encoded access token containing the user details 3:33
-
Pass the access token to the task API endpoints in the authorization header 5:19
-
Validate the access token and decode its contents 5:35
-
Get the authenticated user data from the access token 4:03
Chương 10 Authentication using JSON Web Tokens (JWTs) 8 bài · 28 phút
-
An introduction to JSON web tokens (JWTs) 3:48
-
Create a class to encode a payload in a JWT 5:15
-
Generate a JWT access token in the login endpoint containing JWT claims 2:19
-
Add a method to decode the payload from the JWT 5:34
-
Pass in the secret key used for hashing as a dependency 1:51
-
Authenticate the task endpoints using the JWT 3:40
-
Use a custom exception class to return 401 if the signature is invalid 2:29
-
Don't store sensitive data in the JWT 2:54
Chương 11 Expiring and refreshing access tokens 14 bài · 43 phút
-
Why access tokens need to expire and how to refresh them in a user-friendly way 3:12
-
Add an expiry claim to the access token payload when logging in 2:14
-
Throw a custom exception to not accept the JWT if it has expired 2:19
-
Issue a refresh token in addition to the access token when logging in 2:06
-
Add a refresh endpoint and validate the refresh token in the request 3:41
-
Validate the user in the refresh token using the database 3:11
-
Issue a new access token and refresh token to the authenticated user 2:25
-
Create a table to store a refresh token whitelist 2:19
-
Store the refresh token in the whitelist when issued in the login endpoint 3:48
-
Replace the refresh token in the whitelist when issued in the refresh endpoint 2:50
-
Validate the refresh token is on the whitelist and return a 400 response if not 3:15
-
Add a logout endpoint to remove the an active refresh token from the whitelist 4:18
-
Add a script to clear out expired refresh tokens from the whitelist 3:52
-
See how a single-page application interacts with the API using access tokens 3:34
Chương 12 Conclusion 2 bài · 1 phút
-
Conclusion & where to go from here 1:21
-
Bonus lecture
Requirment
-
You need to know PHP, including the basics of classes and objects, and how to work with a database
-
You need to be happy using the command line, although full instruction on what commands to use will be given
-
Ideally have a web server with PHP and Composer installed, but a brief overview of installing these will be covered
Outcomes
-
Understand how APIs work
-
Learn how to use an API from PHP
-
Create an API from scratch in plain PHP
-
Create, Read, Update, Delete (CRUD) using an API
-
Understand what REST and RESTful APIs are
-
Create a RESTful API in PHP
-
Understand how different API authentication mechanisms work
-
Create API-key authentication for your API
-
Understand how JSON web tokens (JWTs) work, the advantages and disadvantages, and why we use them
-
Understand how HTTP requests and responses work
0 Student
1 Course
0 review