API Interview QnA


1. What is an API
Application Programming Interface (API)
In basic terms, APIs just allow applications to communicate with one another. The API is not the database or even the server, it is the code that governs the access point(s) for the server.



OR it is middle man between UI and Database.

2. What is Microservice and how API testing is beneficial when you are working in MSA.
It is the loosely coupled services which can be developed, deployed, and maintained independently. Each of these services is responsible for discrete task and can communicate with other services through simple APIs to solve a larger complex business problem.
API testing is important to validate that individual microservices is communicating with one another.

3. What are the benefits of API testing
1. Access to application without user interface
2. Time Efficiency vs. functional and validation testing
3. Cost Effective / Reduces Testing Cost
4. Earlier Testing
5. Easier Test Maintenance 

4. Where we can use API testing 
Unit testing, Integration testing(API testing mostly useful), E2E testing and Performance testing

5. What is Rest API and Soap API

Rest API
  • Rest API is implemented as it has no official standard at all because it is an architectural style.
  • REST APIs uses multiple standards like HTTP, JSON, URL, and XML for data communication and transfer.
  • As REST API deploys and uses multiple standards as stated above, so it takes fewer resources and bandwidth as compared to SOAP API.
  • REST API uses Web Application Description Language for describing the functionalities being offered by web services.
  • REST has SSL and HTTPS for security.
  • REST stands for Representational State Transfer.
  • REST can make use of SOAP as the underlying protocol for web services, because in the end it is just an architectural pattern.
SOAP API 
  • On other hand SOAP API has an official standard because it is a protocol.
  • SOAP APIs is largely based and uses only HTTP and XML.
  • On other hand Soap API requires more resource and bandwidth as it needs to convert the data in XML which increases its payload and results in the large sized file.
  • On other hand SOAP API used Web Services Description language for the same.
  • On other hand SOAP has SSL( Secure Socket Layer) and WS-security due to which in the cases like Bank Account Password, Card Number, etc. SOAP is preferred over REST.
  • On other hand SOAP stands for Simple Object Access Protocol
  • On other hand SOAP cannot make use of REST since SOAP is a protocol and REST is an architectural pattern.

6. Difference between REST and SOAP
    It is web services access protocol. While SOAP and REST share similarities over the HTTP protocol, SOAP is a more rigid set of messaging patterns than REST. 
    The rules in SOAP are important because we can’t achieve any level of standardization without them. REST as an architecture style does not require processing and is naturally more flexible. Both SOAP and REST rely on well-established rules that everyone has agreed to abide by in the interest of exchanging information.


7. Difference between Stateless and State Transfer?
Stateless:
    When you open a web page in the browser, you will act as a service consumer and the www server will act as a service provider to serve you with a webpage. If it is a normal connection, the client and the server will both perform a handshake and initiate a session (called a TCP connection).
    After that, based on the server's and client's behavior, the state will change to either ESTABLISHED, IDLE, TIMEOUT, etc. But in REST, we are using the HTTP protocol which is a stateless, meaning the server will not store any session information about the client. The client is responsible for sending all of the details required by the server to get serviced, meaning when we invoke the URI http://somedomain:8080/senthil/services/page1 from the server, it has enough details about the client to serve page1 fully.

State Transfer:
    Using the same example, when you open a web page using some URL to view an image file (RESOURCE) on the server,the www server will show you (the client) the image in some format i.e a REPRESENTATION of the RESOURCE (image file).

During this process, the constant resource state of the server (i.e. the state of the image file which is stored in the server database) will be represented to client in an understandable format i.e. application state of the client. So, the resource state will remain constant in respect to clients, and only the representation of the resource will change, which in turn would change the application state.
    Finally, the representation of the resource (how the image is displayed to the client), which implicitly changes the state of both the server and the client is called REST.


8. What are the HTTP methods in Restful web services?
Create, Read, Update, and Delete are  the HTTP method (CRUD) operations:

HTTP method CRUD Action
GET read returns requested data
POST create creates a new record
PUT or PATCH update updates an existing record
DELETE delete deletes an existing record





  • a GET request to /user/ returns a list of registered users on a systemExamples:
  • a POST request to /user/123 creates a user with the ID 123 using the body data
  • a PUT request to /user/123 updates user 123 with the body data
  • a GET request to /user/123 returns the details of user 123
  • a DELETE request to /user/123 deletes user 123
9. What is Synchronous and Asynchronous API
Synchronous:
    If an API call is synchronous, it means that code execution will block (or wait) for the API call to return before continuing. This means that until a response is returned by the API, your application will not execute any further, which could be perceived by the user as latency or performance lag in your app. Making an API call synchronously can be beneficial, however, if there if code in your app that will only execute properly once the API response is received.

Asynchronous:
    Asynchronous calls do not block (or wait) for the API call to return from the server. Execution continues on in your program, and when the call returns from the server, a "callback" function is executed.


10. Explain REST?
    REST stands for Representational State Transfer. REST is an architectural style of developing web services which take advantage of the ubiquity of HTTP protocol and leverages HTTP method to define actions. It revolves around resource where every component is a resource which can be accessed by a common interface using HTTP standard methods.

In REST architecture, a REST Server provides access to resources and REST client accesses and presents those resources. Here each resource is identified by URIs or global IDs. REST uses different ways to represent a resource like text, JSON, and XML.XML and JSON are the most popular representations of resources these days.


11. Rest vs Restful 
    Representational state transfer (REST) is a style of software architecture. REST is an "architectural style" that basically exploits the existing technology and protocols of the Web.
RESTful is typically used to refer to web services implementing such an architecture.


12. What is JAX-RS and JAX-WS
    JAX-WS, a Java API for the XML-Based Web Services, provided a standard way to develop a Web Services in SOAP (Simple Object Access Protocol) notation.
SOAP protocol is used to exchange of information between the client and the Web Service. Message exchange between the client and the server performed through XML based SOAP messages.
    JAX-RS, a Java API for the XML data exchange or JSON (JavaScript Object Notation) data exchange, provided a flexible way to develop a RESTful Web Services.
REST protocol is used to exchange of information between the client and the Web Service. Message exchange between the client and the server performed through XML and JSON (JavaScript Object Notation)











No comments:

Post a Comment

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post