
Get an introduction to the course, and learn how to get the most out of it.
Find out how to install a web server package, including PHP, a database server like MySQL or MariaDB, and phpMyAdmin, for Windows, macOS or Linux.
Learn how to install the Composer package manager.
Learn exactly what an API (application programming interface) is, and who it's for.
Make a basic API call from PHP code.
Learn what JSON is, and how to decode it in PHP.
Learn how we might integrate API data into a page we view in a browser.
Learn how to use cURL to make a simple API request.
Learn what HTTP status codes are, and how to get them the response using cURL.
Learn what request headers are, and how to add them to the request using cURL.
Learn what response headers are, and how to get them from the response using cURL.
Learn how to get individual response headers in an array using cURL.
Learn an API that requires a specific request header responds.
Learn what request methods are, and how to change it when requesting an API using cURL.
Learn what the request body is, and how to add data to it when requesting an API with cURL.
Learn what the REST architectural style is when developing APIs, and what a RESTful API is.
Learn how to access a RESTful API using cURL.
Learn how to use the Guzzle PHP HTTP client, and see its advantages over file_get_contents and cURL.
Compare an API to an SDK for the same third-party resource.
Enable RESTful URLs by configuring the web server using an .htaccess file.
Add code to get the resource name, optional resource ID and request method in the front controller.
Choose an API client for testing the API - using cURL on the command line, the Postman GUI, or HTTPie, also on the command line.
Set the HTTP status code for the response. Learn which method is the best one to use, based on standards.
Add a class that will act as a controller, deciding which response to return.
Configure Composer'a autoloader to load class files automatically.
Add type declarations to function arguments and return types, and enable strict type checking to make debugging easier.
Add a generic exception handler to make sure that any errors caught are returned as JSON, not HTML. Also add the Content-type header set to JSON to tell the client that the response body contains JSON.
Send a 405 status code if the method is incorrect, along with an Allow header to tell the client which methods are allowed.
Create a new database in the database server and a user to access it that has all necessary privileges. This can be done on the command line or with a tool like phpMyAdmin.
Create a table in the database to store the resource data for the API.
Add a class with the code to connect to the database using PDO.
Add a package to store configuration settings, and move the database connection credentials to a configuration file.
Add a class to act as a table data gateway for the resource table, dependent on the Database class.
Add a method to get all the resource records, and use this to display them as JSON when the index endpoint is called.
Configure the PDO connection to return values in their native format, not all as strings.
Add code to convert boolean values in the database to boolean literals in the JSON.
Add code to select an individual record based on the ID in the URL, and display it as JSON.
Respond with a status code of 404 if the resource with the ID specified in the URL doesn't exist in the database.
Get JSON data from the body of the request for use in inserting and updating data.
Insert a record into the database with data from the request body, and return a 201 status code on success.
Add a generic error handler so that any warnings are also output as JSON in the response body.
Validate the data from the request and respond with a 422 status code if invalid.
Add conditional validation to the request data when updating an existing record.
Get the data from the request body when updating an existing resource.
Update the record in the database with the validated data from the request and return a 200 status code in the response.
Delete the record identified by the ID in the URL and return a 200 status code in the response.
Create a table in the database to store user account data.
Add a register / sign up page to be viewed in a browser to insert a new user account into the database, also generating a new random API key in the process.
Decide if the query string or request header (X-API-Key) is the best place to send the API key with the request.
Check the API key is present in the request and return a status code of 400 if not.
Create a class to act as a table data gateway for the user table, having the Database class as a dependency.
Authenticate the API key and return a 401 status code in the response if the key isn't found in the database.
Refactor the front controller code, reducing code duplication and simplifying the code, to a bootstrap file and Auth class.
Add a foreign key relationship to link the task table to the user table in the database.
Restrict task records to the currently authenticated user in the API.
Restrict all the task records to those associated with the authenticated user ID.
Restricted the rest of the task endpoints to the currently authenticated user's tasks.
Store the database connection in a property of the database class to avoid multiple database connections per request.
Get an introduction to API authentication using access tokens - basically the main point of access tokens is that they can be used without database validation.
Add a login endpoint and return a status code of 400 if the username and password are missing from the request body.
Select the user record from the database based on the username passed in in the request body.
Check the username and password from the request and return a 401 status code if either one is invalid.
Generate an encoded access token containing the user details, using base64 encoding as a simple demonstration.
Get the value of the HTTP authorization header using one of two methods.
Check the access token is valid base64 and JSON.
Get the authenticated user data from the access token's contents, if valid.
Get an introduction to JSON Web Tokens (JWTs).
Create a class from scratch to encode a payload in a JWT.
Generate a JWT access token when requesting the login endpoint that contains specific keys known as JWT claims.
Add a method to the JWT class to decode the payload from a JWT and check its validity.
Extract the secret key used for hashing out to the configuration file, and pass it in as a dependency to the JWT codec class.
Change the front controller so that the task endpoints are authenticated using the JWT instead of the API key.
Add a custom exception class to return a status code of 401 instead of 400 if the signature in the request is invalid.
Learn why you shouldn't store sensitive data in the JWT, as it's only encoded, not encrypted, and can be easily decoded.
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!