Book Image

Learning PHP 7

By : Antonio L Zapata (GBP)
Book Image

Learning PHP 7

By: Antonio L Zapata (GBP)

Overview of this book

PHP is a great language for building web applications. It is essentially a server-side scripting language that is also used for general purpose programming. PHP 7 is the latest version with a host of new features, and it provides major backwards-compatibility breaks. This book begins with the fundamentals of PHP programming by covering the basic concepts such as variables, functions, class, and objects. You will set up PHP server on your machine and learn to read and write procedural PHP code. After getting an understanding of OOP as a paradigm, you will execute MySQL queries on your database. Moving on, you will find out how to use MVC to create applications from scratch and add tests. Then, you will build REST APIs and perform behavioral tests on your applications. By the end of the book, you will have the skills required to read and write files, debug, test, and work with MySQL.
Table of Contents (17 chapters)
Learning PHP 7
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The foundations of REST APIs


Even though REST APIs do not have an official standard, most developers agree on the same foundation. It helps that HTTP, which is the protocol that this technology uses to communicate, does have a standard. In this section, we will try to describe how REST APIs should work.

HTTP request methods

We've already introduced the idea of HTTP methods in Chapter 2, Web Applications with PHP. We explained that an HTTP method is just the verb of the request, which defines what kind of action it is trying to perform. We've already defined this method when working with HTML forms: the form tag can get an optional attribute, method, which will make the form submit with that specific HTTP method.

You will not use forms when working with REST APIs, but you can still specify the method of the request. In fact, two requests can go to the same endpoint with the same parameters, headers, and so on, and yet have completely different behaviors due to their methods, which makes them...