Here we will discuss the two most commonly used API testing tools:
We will be using the following API to demonstrate these tools: JSONPlaceholder - Free Fake REST API. As indicated by its name, it returns fake data, but that is good enough for our purposes here. Click on the Guide menu option on the JSONPlaceholder site to show some examples of how to use the API. The examples use JavaScript code, but for now we will only use the URLs that are passed to the fetch() function in the examples.
The curl command, sometimes spelled as cURL ("client URL"), is a command-line tool that developers use to transfer data to and from a server. You must run it from a terminal window. It is included in the standard installations of Windows and macOS.
The curl command is most often used to quickly GET some data from an API at a specified URL and display it in the terminal window or perhaps redirect the output to a file. The curl command also supports other HTTP methods besides GET, but then the command syntax quickly becomes unwieldy.
Here is an example of a simple GET request to the JSONPlaceholder API. Note that the GET method is used by default and therefore does not need to be specified explicitly on the command line.
curl [<https://jsonplaceholder.typicode.com/todos/1>](<https://jsonplaceholder.typicode.com/todos/1>)
Response:
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
Another curl example, now for a POST request:
curl '[<https://jsonplaceholder.typicode.com/todos>](<https://jsonplaceholder.typicode.com/todos>)'' \\
-X POST \\
-H 'Content-Type: application/json' \\
-d '{"title":"Get a haircut","completed":false,"userId":1}'
Response:
{
"title": "Get a haircut",
"completed": false,
"userId": 1,
"id": 201
}
The backslash character at the end of the first three lines indicates to the terminal that the command continues on the next line. The final line is not terminated with a backslash and represents the end of the command.
-X option specifies the HTTP method-H option is used to specify the request headers, in this case the Content-Type header indicating that the request body will be in the JSON format.-d option is used to specify the body content of the request, in this case a JSON string.<aside> ⌨️
Use curl to try some other GET requests from the JSONPlaceholder examples, for example:
https://jsonplaceholder.typicode.com/todos`https://jsonplaceholder.typicode.com/todos?userId=1`https://jsonplaceholder.typicode.com/todos/1/comments`
</aside>The Postman API testing tool is an application that allows developers and testers to easily build, test, and document APIs. It provides a user-friendly GUI (Graphical User Interface) for interacting with APIs without needing to write complex code.
To install Postman, visit https://www.postman.com/ and click the button to download the desktop app for your computer’s operating system.
When the installation starts you are prompted to create a free account. Without an account the functionality that Postman offers is very limited, so we recommend that you create one.
The picture below shows Postman’s main window.

Let’s try to issue the same GET request as used above with the curl command. Type the first URL in the input box next to the GET button and press the Send button.

In the bottom half of the screen the response will be shown (see screenshot below). The Body tab shows the response content, in this case in JSON format. We can also see that the response status code was 200 OK, which indicates a normal successful response. The response time was 105 ms and the content size is 1.3 KB.

The Headers tab shows the response headers. We can see that the response Content-Type header indicates that the response body is of media type application/json. That is how Postman decided to display the content in the Body tab as JSON.

Postman allows you to save your requests in collections. When you start Postman for the first time it comes with a default collection called “My Collection”. You can now save the GET request in this collection by pressing the Save button.
You can also create a new collection by pressing the New button and select Collection from the pop-up window. You can then enter the name that you want to assign to the collection, for instance “JSONPlaceholder”:

Let’s recreate the POST request that we used earlier with curl, try it and finally save it in the new JSONPlaceholder collection.
](<https://jsonplaceholder.typicode.com/posts>)[<https://jsonplaceholder.typicode.com/posts>`.With all this done, your screen should look like this:

Now press the Send button. If all is well you should get a response that looks like this:

The status code 201 Created indicates that the POST request was successful. The returned JSON data object includes an id property assigned by the JSONPlaceholder server for the newly created post.
You can now save this POST request in the JSONPlaceholder collection by pressing the Save button and selecting the JSONPlaceholder collection. You can recall saved requests by selecting from the collection window.
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **
