Appendix A. Using HTTP as the Network Protocol

 

In this appendix we will learn about

  • The benefits and features of Http which has become the most common network protocol used for microservices today. Note: although our examples will be of Http based API, the ideas in this book are about good design, and are applicable to whatever network protocol you decide to use
  • Http resources and methods, which we will use to define our API
  • Safety, Idempotency, and caching in Http APIs
  • How to deal with API Versioning

This section is a quick review of HTTP protocol, as it applies to microservice API.

Firstly, HTTP is built around the underlying concept of a resource, and a method, which is an action performed on a resource. HTTP gives us nouns and verbs – the nouns are the resource, and the verbs are the methods.

A.1 HTTP Resource

Resources are basically anything that we can interact with on the web – documents, files, and pretty much anything else we can use on the internet. Resources are identified by a Uniform Resource Identifier (URI), which is a way to uniquely identify every resource in the web.

A unique id for every resource in the world – cool, right?

There are different types of URIs, and we are specifically interested in Uniform Resource Locators (URLs), which not only know the name of the resource, but where it is, and how to get to it. I’m sure you know all about URLs. Just as a reminder, they have:

A.2 HTTP Request Methods

A.2.1 Following HTTP Rules, or Be Safe and Idempotent

A.2.2 Safety

A.2.3 Idempotency

A.2.4 Caching

A.3 Encoding the Data into our Request

A.3.1 What Happens if our GET Request is TOO BIG?

A.4 HTTP Response

A.4.1 Headers

A.4.2 Status Codes

A.4.3 Response Body