Chapter 11. The Chef API

In Chapter 10, we met several core Chef objects, such as Chef::Node and Chef::Environment that provide us with an abstraction layer around the underlying API used to communicate with the Chef server. In this chapter, we’re going to look at the API itself and how and why you might want to use it. We’ll learn about:

  • What the Chef API is and why it’s provided
  • The requirements for communicating with Chef’s API
  • How to authenticate to the API
  • How to call API methods
  • The endpoints supported by the API and the data they return
  • The helper classes Chef provides for communicating with the API

We’ll also look at a number of examples of using the Chef API as we work through the chapter.

Introduction to the Chef API

If you take another look at the Chef architecture diagram in Chef Architecture, you’ll see the Erchef component, which provides the core API that enables both Chef’s client tools and the outside world to communicate with Chef server. To use the technical definition, this is an HTTP-based RESTful API that accepts and returns JSON data to allow us to read from and write to a Chef server.

Tip

Entire books have been written about exactly what the term REST means, but for the purposes of this book we’re going to use the definition “structured to make it easy for our code to talk to the API efficiently while still allowing us mere mortals to understand the information that is being exchanged.”

What this means in practical terms is that to ...

Get Customizing Chef now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.