• 4 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 4/2/20

Understand CRUD and Get Data With an API

Log in or subscribe for free to enjoy all this course has to offer!

What the CRUD?

In the last chapter, we spoke about HTTP verbs and how they let you take specific actions when making an API request. Now, we'll look at each one of these verbs, and put them into practice!

CRUD is a popular industry acronym when working with APIs and stands for create, read, update, and delete. While CRUD is not really a technical mechanism, each CRUD action has an associated HTTP verb you can use when working with APIs. The mapping is as follows:

CRUD Action 

Associated HTTP Verb

Create

POST

Read

GET 

Update

PUT

Delete

DELETE

GET to it: Making Your First GET Request

Now that we've covered all the background of an API, let's use one to get some data! We'll be using the GET HTTP verb and the GitHub API (from GitHub) to get data about a specific GitHub user.

To query the API, we'll be using a tool called Postman, which is great for testing REST APIs without having to use any code. This means you can use it no matter what language you're programming in! It has a sleek user interface and is good for beginners making first-time requests. Go ahead and download Postman.  Once you do, you'll be ready to follow along! 

Go ahead and download Postman!
Go ahead and download Postman!

Ready? Start by opening up the program. You'll see a basic user interface like the one below:

Postman user interface
Postman user interface

The first line (highlighted in black) allows you to select your request type from the drop-down menu. Next to that, you can fill in the complete URL of your request. There is a small button (highlighted in red) called Params. If you click it, you have a place to define the key-values of your parameters. Below that (highlighted in blue), you can click on headers. This will allow you to define your request headers. Below that, you can see the body of your response.  

To query the GitHub API about a specific user, you first need to check out the GitHub documentation. This is how you find out what resources, URIs, and endpoints you can use to query data.  Here's an example page of the documentation explaining all the things you can do with the GitHub API related to users:

GitHub Documentation
GitHub documentation

Without documentation, you wouldn't know how to utilize an API! You can see that the URI to GET a single user is  /users/:username.  This means that to get the user information for the user "mbostock", you go into Postman and enter https://api.github.com/users/mbostock in the URL, then click Send.

Our GET request to get a single user with the GitHub API
Yass our first GET request! đź‘Ź

And there you go! You successfully made your first GET request!

GET is the most commonly used HTTP verb and requests specific data from a server. As you saw with the GitHub API, with a GET request you will be getting data by a specific ID; in this case, your GitHub username. You also saw how your browser, or client, uses an API to display the data on a website.

A Quick Note About Documentation

As you can see, proper API documentation is like a detailed user manual. Since each API is different, without clear documentation, you wouldn't know how to use one. Documentation lists all the different possible API calls, typical requests and responses, and which verbs to use with each request. This PetStore API is a good example. 

PetStore API Docs
PetStore API docs

You can see each URI clearly listed with the correct HTTP verb, as well as what the endpoint does!

Let's Recap!

  • CRUD stands for create, read, update, and delete. 

  • GET is the HTTP verb for viewing data and is usually used with an ID.

  • Apps use GET to present information on web pages.

  • Use Postman to test out APIs.

Example of certificate of achievement
Example of certificate of achievement