Solution for Chapter 1: Getting Started with API First

Design and Build Great Web APIs — by Mike Amundsen (112 / 127)

The Pragmatic Programmers
The Pragmatic Programmers
2 min readApr 28, 2021

--

👈 Where’s the Code? | TOC | 2: HTTP, REST, and APIs 👉

In the Chapter Exercise, the task is to use the curl command-line tool to pull a series of responses from three related services (company, account, and activity) and save them to disk for later reference. Here is a step-by-step solution.

First, create a folder called services on your local drive and then change directories to move into that newly created services folder:

Next, using the list supplied in the Chapter Exercise, as a guide, start to pull the API responses from the services and save them to disk. Here’s one way to do this:

The resulting data saved in the file company-home.json will look like this:

You can also use curl in a few other ways to get the same results. Here are some other examples:

This exercise has a total of seven URLs. When you’re done calling all of them, you should have a services folder that looks like this:

You can check the files in the completed folder to compare your API output to the output on the disk.

👈 Where’s the Code? | TOC | 2: HTTP, REST, and APIs 👉

Design and Build Great Web APIs by Mike Amundsen can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

Unlisted

--

--

The Pragmatic Programmers
The Pragmatic Programmers

Published in The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.

The Pragmatic Programmers
The Pragmatic Programmers

Written by The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.