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:
Associated HTTP Verb
GET to it: Making Your First GET Request
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!
Ready? Start by opening up the program. You'll see a basic user interface like the one below:
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:
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.
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.
You can see each URI clearly listed with the correct HTTP verb, as well as what the endpoint does!
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.