This post covers the REST section of the Data Formats and Types chapter when studying for the Zend PHP 7 Certification.
REST is an acronym for Representational State Transfer. It is a design standard (not an extension) and consists of a set of architectural principles for designing web pages and services.
REST applications are supposed to be stateless, which means that the server does not store any state about the client session on the server side.
The applications expose URIs, designed to expose certain aspects of an application’s business logic on a server.
In addition, REST calls can be cached which means it can be reused by the browser later without having to initiate another request back to the server. This saves time and resources.
REST applications can transfer any data formats, for example XML, JSON or both.
The following data types supported include:
REST uses HTTP verbs.
Using REST headers provide information about the entity or other resource that you are requesting.
There are main two concepts:
Status codes used in REST applications include the following:
Using ext
or cURL
is a common way of sending more complex header requests from a PHP script.
Context switching refers to the act of providing different output based on criteria from the request.
The process inspects the HTTP request headers and/or the request URI, and varies the response appropriately. Context switching is commonly used for:
View the other sections:
Note: This article is based on PHP version 7.0.