Solution for Chapter 2: Understanding HTTP, REST, and APIs

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

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

--

👈 1: tarted with API First | TOC | 3: APIs 👉

The task in this exercise is to move our services folder (and all the API calls stored there) into the project repository we created in chapter 2 (see Chapter Exercise).

You can use the before folder for this chapter as a clean start for this exercise. It picks up where our last exercise left off.

Depending on whether you followed along in chapter 2 with the process of creating your onboarding project folder and subsequent changes, you may have some of this exercise already completed. To keep things clear, we’ll start from the beginning by creating a new onboarding folder, making it a git repository, and then copying the services folder into the repository and committing the changes.

Here’s a step-by-step solution.

Create Your Local Git Repo

First, create your onboarding project folder and change directories into that new folder:

Next, make this new empty folder a git repository:

Next, let’s add a README.md file to the repo. It’s always a good idea to use README files to help remember what’s in the repo and why it was created. For this example, we can create a simple text file that contains the following text and save it to disk as a file named “README.md”:

Now do a git status to check the status of the repo:

You’re ready to make your first commit to the repo:

Move the Services Folder into the Repo

Now that you have an up-to-date repository, you’re ready to move the services folder (and all its contents) into that repo and check the repo’s status:

Finally, you can commit the changes (the new folder and its contents) into the Git repository:

Push Your Local Repo to GitHub

Our last task is to push this local repo up to https://github.com to make it publicly available for others. To do that we need to log into your GitHub account, create a repository there, copy the repository address onto our clipboard, and then add that public address to our local repo. Then we can use the git push command to copy our local repo contents to GitHub.

First, log into your GitHub account and click New to start a new repository. Or you can just navigate to https://github.com/new.

Next, fill in the repository name (onboarding) and add a short description (public copy of local onboarding repo). Leave all the other entries as is and click “Create repository,” as shown in the following screenshot:

images/http/exercise-github-new.png

Once that’s created, you’ll see a response screen that contains a lot of text on how to start populating your public repository. For this solution, copy the two lines that appear under the …or push an existing repository from the command line option, as shown in the screenshot. (You should see a small clipboard icon near that text to make it easy to copy the commands.)

images/http/exercise-github-push.png

Paste the commands from your clipboard into your command window and press the Enter key to commit the git push from your local repository to the public one. Your command line should look something like this:

You can check your work by refreshing your project page (from the previous step). You should then see something that looks like this:

images/http/exercise-github-onboarding.png

👈 1: tarted with API First | TOC | 3: 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.