RestAssured#1 - Introduction To API
Source - https://tray.io/blog/how-do-apis-work

RestAssured#1 - Introduction To API

Topics

  1. What is API?
  2. Examples of API Usage
  3. How do API work?
  4. Types of API
  5. What is webservice and its type?
  6. Difference between API and Web service?

What is an API?

API stands for application programming interface. It is a set of functions that allows applications to access data and interact with external software components, operating systems. An API is a software-to-software interface that defines the contract for applications to talk to each other over a network without user interaction.

As per Wikipedia - An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. In contrast to a user interface, which connects a computer to a person, an application programming interface connects computers or pieces of software to each other.

Purpose - In general, APIs define the rules that programmers must follow in order to interact with a programming language, a software library, or any other software tool.

In building applications, an API (application programming interface) simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs. While a graphical interface for an email client might provide a user with a button that performs all the steps for fetching and highlighting new emails, an API for file input/output might give the developer a function that copies a file from one location to another without requiring that the developer understand the file system operations occurring behind the scenes.

Examples of API usage

1. Weather Snippets - One common API usage example we come across on a daily basis is weather data. This is one of common feature of smartphone and can also be found on other platform like Google's search, Apple's weather search. All of this applications use API to fetch weather details.

2. Travel/Hotel Booking - In travel websites we can find multiple flight details based on our search criteria. These travel sites uses API's to find relevant flight from multiple airlines.

As we can see that API's provides an interface to consume service from other application by abstracting underlying implementation of that application.

How do API work?

An API is a set of rules that define how computers, applications, or machines can talk to each other. Most web APIs sit between the application and the web server. The user initiates an API call that tells the application to do something, then the application will use an API to ask the web server to do something. The API is the middleman between the application and the web server, and the API call is the request. And every time you use software to communicate with other software or online web servers, you’re using APIs to request the information you need.

It’s important to note that while web APIs are the most common, APIs aren’t limited to the web. There are APIs for virtually every machine or system that expects to interact with other machines or systems.

Let’s use a metaphor to explain how an API works. Imagine you’re a customer at a restaurant. The waiter (the API) functions as an intermediary between customers like you (the user) and the kitchen (web server). You tell the waiter your order (API call), and the waiter requests it from the kitchen. Finally, the waiter will provide you with what you ordered.

No alt text provided for this image

The waiter is the intermediary between you and the kitchen. In this metaphor, the waiter is effectively an abstraction of the API. In software engineering, an abstraction is a fundamental concept that aims to simplify a complex mechanism by only focusing on the details of higher importance. In this example, as a customer, you don’t need to know how the kitchen or the restaurant operates in order to get what you want: the food. You just need to know how to order it.

An API is also an abstraction of the web server. The application (such as a website or a mobile app) will make an API call for a set of data to display for the end user to consume. The request is made via the API that accesses the web server to retrieve the requested data, which is populated in the user interface.

Types of API

  1. Public APIs - A public API is open and available for use by any outside developer or business.
  2. Partner APIs - A partner API, only available to specifically selected and authorised outside developers or API consumers, is a means to facilitate business-to-business activities.
  3. Internal APIs - An internal (or private) API is intended only for use within the enterprise, to connect systems and data within the business.
  4. Composite APIs - Composite APIs generally combine two or more APIs to craft a sequence of related or interdependent operations. Composite APIs can be beneficial to address complex or tightly-related API behaviours, and can sometimes improve speed and performance over individual APIs.

What is webservice and its type?

A Web service is a software application with a standardised way of providing interoperability between disparate applications. It does so over HTTP using technologies such as XML, SOAP, WSDL, and UDDI. Web services have the advantage of allowing programs developed in different languages to connect with one another by exchanging data over a web service between clients and servers.

A Web Service is can be defined by following ways:

- It is a client-server application or application component for communication.

- The method of communication between two devices over the network.

- It is a software system for the interoperable machine to machine communication.

- It is a collection of standards or protocols for exchanging information between two devices or application.

Types of Webservice

  1. SOAP - s an XML-based Web service protocol to exchange data and documents over HTTP or SMTP (Simple Mail Transfer Protocol). SOAP web services typically use HTTP as a transport protocol, although this is not mandatory. SOAP can be over JMS/FTP/SMTP or any layer 7 protocol. The SOAP message structure consists of an SOAP envelope, inside of which are the SOAP headers and the SOAP body. The SOAP body contains the actual information we want to send. It is based on the standard XML format, designed especially to transport and store structured data. SOAP is a mature standard and is heavily used in many systems, but it does not use many of the functionalities built into HTTP.
  2. REST - RESTful APIs do not need XML-based web service protocols like SOAP and WSDL to support their interfaces. REST is another architectural pattern (resource-oriented), an alternative to SOAP. Unlike SOAP, RESTful applications use the HTTP built-in headers (with a variety of media types) to carry meta-information and use the GET, POST, PUT, and DELETE verbs to perform CRUD operations. REST is resource-oriented and uses clean URLs (or RESTful URLs). The body of can be JSON or XML, the former being preferred more due to its simple structure. Later in this book, we look into the principles of RESTful APIs.

Difference between API and Web service?

- Web Services provide interaction between two machines over a network while APIs acts as an interface between two different applications for interoperability.

- Web Services requires a network connection while APIs may or may not require a network for their operability.

- While APIs can use any protocols or design patterns, web services mostly use REST, SOAP , XML-RPC, or UDDI.

- Many public APIs are transparent with open documentation and self-service portals for rapid developer onboarding. However, web services offer specific data or functionality to certain patterns only.

- Moreover, each web service is an API but all APIs are not web services because a web service might not perform all the operations that an API would do.

- APIs features efficiency, wide reach, personalization, data ownership, time-effectiveness, programming language independence, and easy integration with GUI; Web Services offer loose coupling, synchronous and asynchronous functionality, document exchange support while supporting remote procedure calls.

- Web Services provides support for HTTP only while APIs support HTTP/s, URL Requests/Response Headers and so on.

Saurabh Chaube

QA Manager || Alumni IIM Indore || Project Management -Indian Institute of Management, Indore, Mindtickler || Certified Scrum Master || Ex-Amdocs | QA Automation Engineering || Ex Fiserv

3 年

Anushka Chaube

回复
Pravin Shinde

Software Test Analyst at Encora

3 年

Nice Artical

要查看或添加评论,请登录

Subodh Kumar Singh的更多文章

  • Java #7 - Array (Part-2)

    Java #7 - Array (Part-2)

    Topics Multi-dimensional array (2-Dimensional Array) Array manipulations Multi-dimensional array (2-Dimensional Array)…

  • Java #6 - Array (Part-1)

    Java #6 - Array (Part-1)

    Topics What is an array? One-dimensional array Where is the array saved in memory? What is an array? A variable can…

  • Java #5 - Variables

    Java #5 - Variables

    Topics Variable Types of variable Type Conversion and Casting Type inference - var Variable A variable is a name for a…

  • Java #4 - Data Type

    Java #4 - Data Type

    Topics Where does storage live? Where are primitive types and objects stored in memory? Primitive Types: Data Types in…

  • RestAssured#3-Why to automate webservices/REST API?

    RestAssured#3-Why to automate webservices/REST API?

    Before diving into what and how to test REST API. In this article first lets see why we should bother to test/automate…

    4 条评论
  • RestAssured#2 - Introduction to REST API

    RestAssured#2 - Introduction to REST API

    Topics What is REST API? REST API Principles HTTP Methods - GET, POST, PUT, PATCH and DELETE What is REST API? REST or…

  • Java #3 - Introduction to OOP

    Java #3 - Introduction to OOP

    In this article, will discuss on below topics:- What are programming paradigm? What is OOP? Features of OOP? Is Java a…

  • Java #2 - Java Overview

    Java #2 - Java Overview

    In this article, will discuss on below topics:- How Java is platform independent and secure? Writing First Java Program…

  • Java #1 - History of Java

    Java #1 - History of Java

    In this article, will discuss on below topics:- A brief history of C and C++ History of Java Why Java was created? A…

社区洞察

其他会员也浏览了