Web Development · WDC-61

PHP and MySQL RESTful API

PHP and MySQL RESTful API is a course in building RESTful APIs with PHP 8.5 and MySQL without a framework, from REST principles, routing and PDO to consistent JSON responses, Basic Auth and JWT authentication, and calling APIs with the Fetch API and Guzzle. It suits web developers, students and IT staff who already have some PHP and MySQL experience.

Updated
From 5,850 THB / person 6,500 −10% excl. VAT 7% · group rates available
PDFDownload the course outline
  • Duration12 hours · 2 days
  • FormatOnsite / live online
  • Next roundOn request
  • CertificateIncluded

Course overview

REST is a way of designing web services that treats data as resources reached through URLs, communicates statelessly and uses HTTP methods such as GET, POST, PUT and DELETE for their intended meaning, returning JSON that mobile apps, web pages and other systems can consume. Writing an API in PHP without a framework shows how every layer works, from handling the request and accessing the database to authentication, and that understanding carries over to any framework.

This course builds a RESTful API with PHP 8.5 and MySQL without a framework. It starts with REST and HTTP principles, then a hand-written front controller and router, database access with PDO, endpoints for articles and categories, and systematic validation and error responses. Learners secure the API with Basic Auth and JWT, build a single-page web front end that calls it, call external services with Guzzle, and finish with a workshop and deployment. (2 days, 6 hours per day, 12 hours in total, Intermediate level.)

What you’ll gain

  • Understand REST principles, HTTP methods, status codes and the headers APIs use
  • Write a front controller and router for an API in PHP 8.5 without a framework
  • Access MySQL safely with PDO and prepared statements
  • Build endpoints that validate input and return consistent JSON errors
  • Secure the API with Basic Auth and JWT, and configure CORS
  • Call the API from a web page with the Fetch API and call external APIs with Guzzle
  • Document the API and deploy it to production

Who this course is for

  • Web developers who write PHP and want to build web services for other systems
  • Developers who want to understand how an API works before using a framework
  • Students, teachers and lecturers interested in API development
  • IT staff and system administrators who connect systems through APIs

Prerequisites

  • Able to write PHP, with a basic understanding of classes and objects
  • Able to write basic SQL, with some experience of MySQL
  • Basic web design knowledge with HTML, CSS and some JavaScript
  • A laptop that can run Docker Desktop or PHP 8.4 or later, Composer, VS Code and Postman, with permission to install software

Curriculum

Course Details

This course is the 2026 edition of PHP and MySQL RESTful API. It runs for 2 days, 6 hours per day (12 hours in total, 09:00-16:00), as lectures with labs and a workshop. Intermediate level. This edition uses PHP 8.5 and MySQL 9.7 LTS on Docker Compose instead of XAMPP, VirtualBox and Vagrant. It keeps the plain PHP approach without a framework and the article and category API project, and adds

a hand-written router, validation and standard error formats, CORS, API security guidance, OpenAPI documentation and deployment. Basic Auth, JWT, the single-page web front end and Guzzle are kept. The course focuses on APIs, unlike PHP OOP and MySQL, which focuses on OOP and design patterns; learners who want a framework can continue with RESTful API with Laravel. Learners take home a lab guide, source code for every lab and a Postman collection.

Day 1 REST, Routing and First Endpoints

Section 1: Getting to Know REST and HTTP

  • What REST is, and how REST and RESTful differ
  • Common HTTP methods, status codes and headers for APIs
  • HTTP/1.1, HTTP/2 and HTTP/3 from an API developer's point of view
  • Resource-based endpoint design, such as /articles and /categories

Section 2: Lab: Setting Up the Tools

  • Run PHP 8.5 and MySQL 9.7 LTS with Docker Compose
  • Composer and PSR-4 autoloading
  • VS Code, Git and Postman or .http files
  • Lab: a starter project with a sample database

Section 3: A Hand-Written Front Controller and Router

  • Send every request through public/index.php with clean URLs
  • Match the method and path to the right controller
  • Read JSON from php://input and respond with json_encode
  • Lab: a small router that supports URL parameters

Section 4: Lab: MySQL Access with PDO

  • A PDO connection class with utf8mb4 and exception error mode
  • Prepared statements to prevent SQL injection
  • Models for users, articles and categories
  • Transactions when saving to several tables

Section 5: Lab: Article and Category Endpoints

  • GET a list of articles with pagination and search
  • POST, PUT, PATCH and DELETE with correct status codes
  • Articles by category and the latest articles
  • Test every endpoint in Postman

Section 6: Validation and Consistent Errors

  • Validate input and return 422 with details
  • Central exception handling with JSON error responses
  • Error format following Problem Details (RFC 9457)
  • Log errors without exposing internal details
Day 2 Authentication, Consuming APIs and Workshop

Section 7: Lab: Sign-Up and Basic Auth

  • A sign-up endpoint with password_hash
  • Check passwords with password_verify
  • Basic Auth in the Authorization header, and why HTTPS is required
  • The limits of Basic Auth compared with tokens

Section 8: Lab: Authentication with JWT

  • The structure of a JWT: header, payload and signature
  • Create and verify tokens with firebase/php-jwt
  • Set expiry times and handle expired tokens
  • Middleware that checks the bearer token before an endpoint

Section 9: CORS and API Security

  • CORS and preflight requests when calling from JavaScript
  • Simple request rate limiting
  • Check data ownership before updates and deletes
  • A checklist based on the OWASP API Security Top 10

Section 10: Lab: A Single-Page Web Front End for the API

  • A page built with HTML, Bootstrap 5 and the Fetch API
  • Sign up, log in and store the token with care
  • Create articles and list them by category
  • Show API errors in a way users understand

Section 11: Lab: Calling External APIs with Guzzle

  • Install Guzzle with Composer
  • Send GET and POST requests with query strings and JSON
  • Asynchronous requests and concurrent requests with a pool
  • Handle timeouts and errors from external services

Section 12: Workshop: The Article API with Documentation, Deployed

  • Combine every endpoint with JWT authentication
  • Document the API with OpenAPI
  • Deploy to a web server with public as the document root
  • Use an AI assistant to review code with care, and next steps towards a framework

Schedule & training options

For individuals — public rounds

No public rounds are open right now. Join the waiting list and we will contact you first when the next round opens, or ask us on LINE. Or call 02-570-8449 or 088-807-9770

For organisations — in-house / private

  • Tailor the content to your team’s tools and projects
  • Your dates, at your office or live online
  • Quotation with tax ID for procurement
Corporate training quote

Instructors

Frequently asked questions

What is the difference between REST and RESTful?

REST (Representational State Transfer) is an architectural style for web services that treats data as resources reached through URLs and communicates statelessly, so every request carries everything it needs and the server does not remember earlier requests. RESTful describes an API or service that genuinely follows REST, for example using GET, POST, PUT and DELETE for their intended meaning and replying with suitable HTTP status codes.

How do I start building a PHP and MySQL API that returns JSON?

Start by designing the MySQL tables and defining endpoints by resource, such as /articles. Route every request through public/index.php and use a router to dispatch by HTTP method and path. Access the database with PDO and prepared statements, read input from php://input with json_decode, and reply with the Content-Type: application/json header, json_encode and the correct http_response_code. Then test with Postman.

What is the difference between Basic Auth and JWT?

Basic Auth sends the username and password, encoded in Base64, with every request in the Authorization header. Base64 is easy to decode, so it must always be used over HTTPS. With JWT the user logs in once and receives a token signed by the server, then sends the token instead of the password on later requests. The token can expire and carries data such as the user ID, so the server can check access without keeping a session.

Who is the PHP and MySQL RESTful API course for, and what should I know beforehand?

It suits web developers who want to build web services for other systems, developers who want to understand how APIs work before using a framework, students, teachers, lecturers, IT staff and system administrators. You should be able to write PHP with a basic grasp of classes and objects, write SQL with some MySQL experience, and know basic HTML, CSS and JavaScript.

What will I be able to do after the PHP and MySQL RESTful API course?

You will be able to design and write an API with PHP 8.5 and MySQL without a framework, including the router, PDO access and endpoints for sign-up, user checks and article and category management, with systematic validation and errors. You will secure it with Basic Auth and JWT, configure CORS, build a single-page front end that calls it, use Guzzle to call other APIs, document it with OpenAPI and deploy it. Participants receive a Certificate of Completion with its own number that can be verified online.

What software and tools does the PHP and MySQL RESTful API course use?

You use Docker Desktop to run PHP 8.5 and MySQL 9.7 LTS through Docker Compose, or a locally installed PHP, Composer to install packages such as firebase/php-jwt and Guzzle, Visual Studio Code with PHP extensions, Git, and Postman for testing the API. These are installed at the start of the course. This edition no longer uses XAMPP, VirtualBox or Vagrant.

Related articles

Articles are published in Thai.