Learn API for Testers

Tram Ho

In the modern technology world, API (Application Programming Interface) is a common term used in software development.

First of all, I would like to say hello to everyone, have a good day at work and study. In this article, I will introduce the basic knowledge related to API. Let’s get into the content of the article!

1. What is an API?

API stands for “Application Programming Interface”, which is a way for other software to interact with each other. This is a type of interface that a software application uses to allow other applications to use its functionality or manipulate its data.

Examples of APIs in real life :

  • Smart Device Control : Smart devices like Amazon Echo, Google Home,… provide APIs for app developers so they can control these smart devices. For example, you can use your phone app to control the expansion of your home’s temperature or turn on and off smart lights through the Amazon Echo API.
  • Amazon’s Kindle Reading App : Amazon’s Kindle reading app provides an API that allows other apps to sync data and access books purchased from Amazon. For example, if you buy a book from Amazon on its website, you can use the Kindle app to read it on your mobile phone.

In short, API has become very important technology in information technology applications. They make it possible for different applications to access and interact with each other to provide better user experiences.

Illustrate the API with a restaurant dining situation. When you come to the restaurant, the waiter will give you the menu to order, the main waiter is API

image.png

After you have finished choosing the dish, the request will be sent to the chef for fulfillment. The main chef is App

image.png

When the dish is done, the waiter will bring it to you. You are the User

image.png

So let’s summarize. The staff will have the role of connecting you and the chef. API is a mechanism for User and App to communicate with each other

image.png

2. What is RESTfulAPI?

RESTful API (Representational State Transfer API) is a type of web architecture based on HTTP protocol to transfer data. It is one of the most popular architectures for creating web APIs. RESTful API defines URLs and HTTP methods to perform operations on resources, and provides standard data formats such as JSON, XML for data exchange between server and client.

RESTfulAPI example :

Twitter is a popular social network used worldwide. Twitter provides a RESTful API that allows third-party application developers to access and retrieve data from a user’s posts, account information, friends list,… through endpoints. APIs. HTTP methods include GET, POST, PUT, DELETE and the transmitted data format is JSON or XML.

Example: To get a list of posts for a Twitter account, we can use the endpoint: ” https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={screen_name}&count ={count} ” and a GET method to get a list of user posts with a default count of 20.

3. API Testing

API testing is the process of testing software to ensure the functionality, stability, security, and interoperability of APIs. API testing is commonly used to test the adequacy of endpoints, execute HTTP methods (like GET, POST, PUT, DELETE) on APIs and check the returned data.

API Testing use case example :

For example, GitHub is a widely used source code hosting service by developers around the world. GitHub provides a RESTful API that allows third-party application developers to access and retrieve data about repositories, issues, pull requests,… through API endpoints.

To test the adequacy of an API endpoint that returns a list of user repositories in GitHub, you can perform the following steps:

  • Make a GET request with the HTTP method to send the request to the endpoint ” https://api.github.com/users/{username}/repos “, where {username} is the username on GitHub.
  • Check that the request was sent successfully and received a response from the server. Check if the response contains necessary information such as repository name, description, URL.
  • Check the correctness of the returned data by comparing with the correct data (if any).

4. Summary

In short, API is a widely used technique in software programming. RESTful API is a version of the API built on top of the REST programming interface style, and API Testing is an important software testing technique in ensuring the correctness and safety of the API. Through this article, I hope this is useful knowledge for everyone.

Finally, thank you to everyone who read the article!

Share the news now

Source : Viblo