API Interview Questions And Answers
by Rupa.R, on Sep 9, 2022 5:01:06 PM
Q1. What is Api?
Ans: An API (Application Programming Interface) is a collection of software functions and procedures, called API calls, that can be executed by other software applications. Application developers code that links to existing APIs to make use of their functionality. This link is seamless and end-users of the application are generally unaware of using a separately developed API.
During testing, a test harness-an application that links the API and methodically exercises its functionality-is constructed to simulate the use of the API by end-user applications. The interesting problems for testers are:
1. Ensuring that the test harness varies parameters of the API calls in ways that verify functionality and expose failures. This includes assigning common parameter values as well as exploring boundary conditions.
2. Generating interesting parameter value combinations for calls with two or more parameters.
3. Determining the content under which an API call is made. This might include setting external environment conditions (files, peripheral devices, and so forth) and also internal stored data that affect the API.
4. Sequencing API calls to vary the order in which the functionality is exercised and to make the API produce useful results from successive calls.
Q2. Explain what is REST and RESTFUL?
Ans: REST represents REpresentational State Transfer; it is relatively new aspect of writing web api.
RESTFUL is referred for web services written by applying REST architectural concept are called RESTful services, it focuses on system resources and how state of resource should be transported over HTTP protocol to a different clients written in different language. In RESTFUL web service http methods like GET, POST, PUT and DELETE can be used to perform CRUD operations.
Q3. Explain the architectural style for creating web api?
Ans: The architectural style for creating web api are
- HTTP for client server communication
- XML/JSON as formatting language
- Simple URI as the address for the services
- Stateless communication
Q4. Mention what tools are required to test your web api?
Ans: SOAPUI tool for SOAP WS and Firefox “poster” plugin for RESTFUL services.
Q5. Mention what are the HTTP methods supported by REST?
Ans: HTTP methods supported by REST are:
- GET: It requests a resource at the request URL. It should not contain a request body as it will be discarded. May be it can be cached locally or on the server.
- POST: It submits information to the service for processing; it should typically return the modified or new resource
- PUT: At the request URL it update the resource
- DELETE: At the request URL it removes the resource
- OPTIONS: It indicates which techniques are supported
- HEAD: About the request URL it returns meta information
Q6. Mention whether you can use GET request instead of PUT to create a resource?
Ans: No, you are not supposed to use POST or GET. GET operations should only have view rights.
Q7. Mention what are resources in a REST architecture?
Ans: Resources are identified by logical URLs; it is the key element of a RESTful design. Unlike, SOAP web services in REST, you view the product data as a resource and this resource should contain all the required information.
Q8. Mention what is the difference between AJAX and REST?
Ans:
AJAX | REST |
· In Ajax, the request are sent to the server by using XMLHttpRequest objects. The response is used by the JavaScript code to dynamically alter the current page
· Ajax is a set of technology; it is a technique of dynamically updating parts of UI without having to reload the page · Ajax eliminates the interaction between the customer and server asynchronously · REST requires the interaction between the customer and server |
· REST have a URL structure and a request/response pattern the revolve around the use of resources
· REST is a type of software architecture and a method for users to request data or information from servers · REST requires the interaction between the customer and server |
Q9. Mention some key characteristics of REST?
Ans: Some key characteristics of REST includes
- REST is stateless, therefore the SERVER has no state (or session data)
- With a well applied REST API, the server could be restarted between two calls as every data is passed to the server
- Web service mostly uses POST method to make operations, whereas REST uses GET to access resources
Q10. Mention what are the different application integration styles?
Ans: The different integration styles includes
- Shared database
- Batch file transfer
- Invoking remote procedure (RPC)
- Swapping asynchronous messages over a message oriented middle-ware (MOM)
Q11. Explain how JAXB related to RESTful web api?
Ans: JAXB stands for java arch for xml binding.
Q12. Mention what is the difference between PUT and POST?
Ans: “PUT”puts a file or resource at a particular URI and exactly at that URI. If there is already a file or resource at that URI, PUT changes that file or resource. If there is no resource or file there, PUT makes one
POST sends data to a particular URI and expects the resource at that URI to deal with the request. The web server at this point can decide what to do with the data in the context of specified resource
Q13. Mention which markup language can be used in restful web api?
Ans: JSON and XML are the two markup language that can be used in restful web api
Q14. Mention what is the difference between RPC or document style web services? How you determine to which one to choose?
Ans: In document style web services, we can transport an XML message as part of SOAP request which is not possible in RPC style web service. Document style web service is most appropriate in some application where XML message behaves as document and content of that document can alter and intention of web service does not rely on the content of XML message.
Q15. Mention what is JAX-WS and JAX-RS?
Ans: Both JAX-WS and JAX-RS are libraries (APIs) for doing communication in various ways in Java. JAX-WS is a library that can be used to do SOAP communication in JAVA, and JAX-RS lets you do the REST communication in JAVA.
Q16. List out the tools or API for developing or testing web api?
Ans: Testing tools for web services for REST APIs includes
- Spring REST web service using MVC
- Jersey API
- CFX
- Axis
- Restlet,
Q17. Mention what is the difference between SOAP and REST?
Ans:
SOAP | REST |
· SOAP is a protocol through which two computer communicates by sharing XML document
· SOAP permits only XML |
· Rest is a service architecture and design for network-based software architectures
· REST supports many different data formats · REST is faster than SOAP |
API Testing and API Rest Interview Questions and answers:
Q1. What is API testing?
Ans: API (Application Programming Interface) specifies how some software components should interact with other, in other words it’s a set of functions and procedures that allows the creation of applications which access the features or data of an application or operating system. Testing of these functions is known as API testing.
Q2. What are the tools used for API testing?
Ans: The tools used for various API testing are
- SoapUI Pro
- LoadUI Pro
- Alertsite API monitoring
Q3. What are the common tests performed on API’s?
Ans: The common tests performed on API’s
- Verification of the API whether it is updating any data structure
- Verify if the API does not return anything
- Based on input conditions, returned values from the API’s are checked
- Verification of the API whether it triggers some other event or calls another API
Q4. Mention the key difference between UI level testing and API testing?
Ans: UI ( User Interface) refers to testing graphical interface such as how user interacts with the applications, testing application elements like fonts, images, layouts etc. UI testing basically focuses on look and feel of an application.
While, API enables communication between two separate software systems. A software system implementing an API contains functions or sub-routines that can be executed by another software system
Q5. Explain what is SOAP?
Ans: SOAP-stands for Simple Object Access Control, and it is an XML based protocol for exchanging information between computers.
Q6. Explain what is REST API?
Ans: It is a set of functions to which the developers performs requests and receive responses. In REST API interaction is made via HTTP protocol
REST – stands for Representational State Transfer, it is quickly becoming defacto standard for API creation.
- 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.
Q7. Difference API and Unit Testing?
Ans:
API testing | UNIT testing |
· API is owned by QA team | · Unit testing is owned by development team |
· API is mostly black box testing | · Unit testing is white box testing |
· Full functionality of the system is considered in API testing as it will be used by the end-user (external developers who will use your API ) | · Unit testing is done to verify whether each unit in isolation performs as expected or not |
· API test are often run after the build is ready and authors do not have access to the source code | · For each of their module the developers are expected to build unit tests for each of their code modules and have to ensure that each module pass unit test before the code is included in a build |
Q8. How to test API’s ?
Ans: To test the API’s you should follow the following steps
- Select the suite in which you want to add the API test case
- Choose test development mode
- Develop test cases for the desired API methods
- Configure application control parameters
- Configure test conditions
- Configure method validation
- Execute API test
- View test reports
- Filter API test cases
- Sequence API test cases
Q9. Mention what the main areas to be taken in consideration while writing API document ?
Ans: The key area to be considered when writing API documents are
- Source of the content
- Document plan or sketch
- Delivery layout
- Information required for each function in the document
- Automatic document creation programs
Q10. In API document explain how to document each function ?What are the tools used for documentation?
Ans:
- Description:Small description about what a function does
- Syntax:Syntax about the parameter of the code, the sequence in which they occur, required and optional elements etc.
- Parameters:Functions parameters
- Error Messages:Syntax of error messages
- Example Code:Small snippet of code
- Related Links:Related functions
Popular tools used for API documentations are JavaDoc (for Java code ) Doxygen (for .Net code)
Q11. Explain API framework?
Ans: API framework is self-explanatory. Values for test run and for holding the configurable parts, config file is used. Automated test cases must represent in “ parse-table” format within config file. When testing API, it is not necessary to test each API so the config file have some section whose all API are activated for that specific run.
Q12. How does the API Builder work?
Ans: API Builder is a PLSQL program consists of four SQL files
- For setting API parameters and starting the process one file is responsible
- Two files are created for temporary tables and Master package to create the outputted code
- Fourth file creates “spooled” output of the code into a file called “output_script_.sql”
Q13. Explain what is TestApi ?
Ans: TestApi is a library of utility and test APIs that enables testers and developers to create testing tools and automated tests for .NET and Win32 application. It provides a set of common test building blocks, types, data-structure and algorithms.
Q14. What is Input injection and what are different ways of doing it ?
Ans: Input Injection: It is the act of simulating user input, in several ways you can simulate user input.
- Direct Method Invocation
- Invocation using an accessibility interface
- Simulation using low-level input
- Simulation using a device driver
- Simulation using a robot
Q15. What are the main challenges of API testing?
Ans: The main challenges in API testing is
- Parameter Selection
- Parameter Combination
- Call sequencing
Q16. What is API testing with runscope ?
Ans: Runscope is a web application that provides backend services and easy to use interface for testing APIs.
Q17. Explain what are the principles of API test design?
Ans: The principle for API test design are
- Setup :Create objects, start services, initialize data etc
- Execution:Steps to exercise API or scenario, also logging
- Verification:Oracles to evaluate execution outcome
- Reporting:Pass, failed or blocked
- Clean up:Pre-test state
Q18. What are the types of Bugs will API testing finds?
Ans: The types of Bugs, API will find
- Missing or duplicate functionality
- Fails to handle error conditions gracefully
- Stress
- Reliability
- Security
- Unused flags
- Not implemented errors
- Inconsistent error handling
- Performance
- Multi-threading issues
- Improper errors
Q19. What are the tools used for API test automation?
Ans: While testing Unit and API testing, both target source code, if an API method is using code based on .NET then the tool which is supporting should have .NET
Automation tools for API testing can be used are
- NUnit for .NET
- JUnit for Java
- HP UFT
- Soap UI
Q20. Mention the steps for testing API ?
Ans: API testing steps
- Select the test case that has to be fulfilled
- For API call develop a test case
- To meet the test case configure the API parameters
- Determine how will you validate a successful test
- Using programming language like PHP or .NET execute the API call
- Allow the API call to return the data to validate
Q21. What are the common protocols that are testing in API tesing ?
Ans:
- HTTP
- JMS
- REST
- SOAP
- UDDI
Q22. Explain The RESTFul Web Service?
Ans:
- Mostly, there are two kinds of Web Services which are quite popular.
- SOAP (Simple Object Access Protocol) which is an XML-based way to expose web services.
- Web services developed using REST style are known as RESTful web services. These web services use HTTP methods to implement the concept of REST architecture. A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.
Q23. Explain What Is A “Resource” In REST?
Ans:
- REST architecture treats every content as a resource. These resources can be either text files, HTML pages, images, videos or dynamic business data.
- REST Server provides access to resources and REST client accesses and modifies these resources. Here each resource is identified by URIs/ global IDs.
Q24. What Is The Most Popular Way To Represent A Resource In REST?
Ans: REST uses different representations to define a resource like text, JSON, and XML.
XML and JSON are the most popular representations of resources.
Q25. Which Protocol Is Used By RESTful Web Services?
Ans: RESTful web services make use of HTTP protocol as a medium of communication between client and server.
Q26. What Is Messaging In RESTful Web Services?
Ans: RESTful web services make use of HTTP protocol as a medium of communication between client and server. The client sends a message in the form of an HTTP Request.
In response, the server transmits the HTTP Response. This technique is called Messaging. These messages contain message data and metadata i.e. information about the message itself.
Q27. State The Core Components Of An HTTP Request?
Ans: Each HTTP request includes five key elements.
- The Verb which indicates HTTP methods such as GET, PUT, POST, DELETE.
- URI stands for Uniform Resource Identifier (URI).It is the identifier for the resource on the server.
- HTTP Version which indicates HTTP version, for example-HTTP v1.1.
- Request Header carries metadata (as key-value pairs) for the HTTP Request message. Metadata could be a client (or browser) type, the format that client supports, message body format, and cache settings.
- Request Body indicates the message content or resource representation.
Q28. State The Core Components Of An HTTP Response?
Ans: Every HTTP response includes four key elements.
- Status/Response Code – Indicates Server status for the resource present in the HTTP request.For example, 404 means resource not found and 200 means response is ok.
- HTTP Version – Indicates HTTP version, for example-HTTP v1.1.
- Response Header – Contains metadata for the HTTP response message stored in the form of key-value pairs. For example, content length, content type, response date, and server type.
- Response Body – Indicates response message content or resource representation.
Q29. Name The Most Commonly Used HTTP Methods Supported By REST?
Ans: There are a few HTTP methods in REST which are more popular.
- GET -It requests a resource at the request-URL. It should not contain a request body as it will get discarded. Maybe it can be cached locally or on the server. 2.POST – It submits information to the service for processing; it should typically return the modified or new resource. 3. PUT – At the request URL it updates the resource. 4. DELETE – It removes the resource at the request-URL. 5. OPTIONS -It indicates the supported techniques. 6. HEAD – It returns meta information about the request URL.
Q30. Mention, Whether You Can Use GET Request Instead Of PUT, To Create A Resource?
Ans: No, you shouldn’t use a PUT or POST method. Instead, apply the GET operation which has view-only rights.
Q31. Is There Any Difference Between PUT And POST Operations? Explain It.
Ans: PUT and POST operation are almost same. The only difference between the two is in the terms of the result generated by them.
PUT operation is idempotent while POST operation can give a different result.
Let’s take an example.
- PUT puts a file or resource at a particular URI and exactly at that URI. If the resource already exists, then PUT updates it. If it’s a first-time request, then PUT creates one.
- POST sends data to a particular URI and expects the resource at that URI to deal with the request. The web server at this point can decide what to do with the data in the context of specified resource.
Q32. What Purpose Does The OPTIONS Method Serve For The RESTful Web Services?
Ans: This method lists down all the operations a web service supports. It makes read-only requests to the server.
Q33. What Is URI? Explain Its Purpose In REST Based Web Services. What Is Its Format?
Ans: URI stands for Uniform Resource Identifier. URI is the identifier for the resource in REST architecture.
The purpose of a URI is to locate a resource(s) on the server hosting the web service. A URI is of the following format
Q34. What Do You Understand By Payload In RESTFul Web Service?
Ans: Request body of every HTTP message includes request data called as Payload. This part of the message is of interest to the recipient.
We can say that we send the payload in POST method but not in <GET> and <DELTE> methods.
Q35. What Is The Upper Limit For A Payload To Pass In The POST Method?
Ans: <GET> appends data to the service URL. But, its size shouldn’t exceed the maximum URL length. However, <POST> doesn’t have any such limit.
So, theoretically, a user can pass unlimited data as the payload to POST method. But, if we consider a real use case, then sending POST with large payload will consume more bandwidth. It’ll take more time and present performance challenges to your server. Hence, a user should take action accordingly.
Q36. Explain The Caching Mechanism?
Ans: Caching is a process of storing server response at the client end. It makes the server save significant time from serving the same resource again and again.
The server response holds information which leads a client to perform the caching. It helps the client to decide how long to archive the response or not to store it at all.
Q37. What Are The Tools Available For Testing Web Services?
Ans: Following tools can help in testing the SOAP and RESTful web services.
- SOAP UI tool.
- Poster for Firefox browser.
- The Postman extension for Chrome.
Q38. Explain The Factors That Help To Decide About The Style Of Web Service To Use? SOAP Or REST?
Ans: In general, using REST based web service is preferred due to its simplicity, performance, scalability, and support for multiple data formats.
However, SOAP is favorable to use where service requires an advanced level of security and transactional reliability.
But you can read the following facts before opting for any of the styles.
- Does the service expose data or business logic? To expose data REST will be a better choice and SOAP for logic.
- If the consumer or the service providers require a formal contract, then SOAP can provide such a contract via WSDL.
- Need to support multiple data formats. REST supports this.
- Support for AJAX calls. REST can use the XMLHttpRequest.
- Synchronous and asynchronous calls – SOAP enables both synchronous/asynchronous operations whereas REST has built-in support for synchronous.
- Stateless or Stateful calls -REST is suited for stateless operations.
Here are some of the advanced-level facts that you can consider as well.
- Security requirement – SOAP provides a high level of security.
- Transaction support – SOAP has good support for transaction management.
- Limited bandwidth – SOAP has a lot of overhead when sending/receiving packets since it’s XML based, requires a SOAP header. However, REST requires less bandwidth to send requests to the server. Its messages are mostly built using JSON.
- Ease of use – It is easy to implement, test, and maintain REST based application.
Q39. Can You Tell Us Which Java API Helps In Developing A RESTFul Web Service?
Ans: There are many frameworks and libraries available that a developer can use to create RESTful web services in Java. For example, the JAX-RS library is a standard way to develop a REST web service.
Also, Jersey is another most popular implementations of JAX-RS which offers more than what the specs recommend. There are others like RESTEasy, RESTlet, and Apache CFX.
If you like Scala, then you should be using Play framework to develop RESTful web services.
Q40. Name The Most Commonly Used HTTP Methods Supported By REST?
Ans: There are a few HTTP methods in REST which are more popular.
- GET -It requests a resource at the request-URL. It should not contain a request body as it will get discarded. Maybe it can be cached locally or on the server.
- POST – It submits information to the service for processing; it should typically return the modified or new resource.
- PUT – At the request URL it updates the resource.
- DELETE – It removes the resource at the request-URL.
- OPTIONS -It indicates the supported techniques.
- HEAD – It returns meta information about the request URL.