HTTP is one of the important protocols underlying the WordPress REST API and the web at large.  In this ~20 minute video we go over all the important aspects of HTTP that you should know about as you prepare to work with the WordPress REST API or any other APIs using JavaScript or other languages.

Some Important Terms:

  • Hypertext Transfer Protocol (HTTP) – A standard for making requests and responses between clients and servers.
  • HTTP Clients – Applications like web browsers or JavaScript apps that make requests to web servers.
  • HTTP Servers – Computers running software like Apache or NGIX that understand HTTP requests and responses.
  • HTTP Requests – Made from a client to a server. Several Request Methods like GET, POST, PUT, DELETE are available. More than just requesting information, can also do things like post new posts or pages in the case of WordPress or edit existing content.
  • HTTP Responses – Made from a server to a client in response to a request.
  • HTTP Messages – The bundle of data passed in requests and respones are referred to as messages. Includes [1] Request or Status Line, [2] Headers, [3] Message Body (optional)
  • HTTP Request Line (w Requests) – Includes the Request Method (GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE), the URI of the page or resource you want to access and the HTTP Version (1.1 is most common, although 2.0 was standardized in 2015 though not fully implemented across the web). This line is only included if we are sending a request.Example: GET javascriptforwp.com HTTP/1.1
  • HTTP Status Line (w Responses) – Includes: HTTP Version, Status Code (1XX informational, 2XXX success, 3XX redirect, 4XX client error, 5XX server error)Examples:
    HTTP/1.1 200 OK
    HTTP/1.1 404 Not Found
  • HTTP Headers – Includes metadata for each request and response sent.  Standard header fields (or metadata options) exist and custom header fields can be created as well.
  • HTTP Message Body – Optional data passed along with a request or response.  For a POST request it could be the new post information like title and content.  For a response we might get an HTML webpage or media asset or JSON in the case of the WP API.

A Brief History of HTTP

  • 1989 – Tim Berners-Lee and his team at CERN
    – Started with ability for a client to send a GET request to a server
    – HTML created at same time as a markup language text sent via HTTP (and we see CSS, and JavaScript come out of this birth as well)
  • 1991 – V 0.9
  • 1996 – V 1.0 – Opened a new connection for each request
  • 1997 – V 1.1 – Allowed for single connection to be used for multiple requests
  • 2015 – V 2.0 – Streams and Multiplexing

To Learn How to Make HTTP Requests

In the JavaScript for WordPress Master Course we learn about how to make all sorts of HTTP requests to the WordPress REST API using the browser, Postman, JavaScript, PHP and the Command Line.