Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

1-What Is An API?: //asked in Interview

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

● API is an interface that enables two applications to communicate without any network.

● Rest is an architectural style that uses to create web services


● Rest API is a set of functions used by the developers to send requests and receive
responses.

WebService : A WebService is any piece of software that makes itself available over the internet.
It is an API which is wrapped over HTTP protocol. Webservice is a way for two machines to
communicate with each other over a network. Unlike web applications, web services are designed to
interact with another program rather than interacting directly to the user.
Web Services uses only three styles REST , SOAP , XML-RPC(Remote Procedure Call).

Types of Web Service :


There are three types of Web Service - REST , SOAP , XML-RPC

//Asked in interview
1- What is an API?
Api is a software interface that enables two applications to communicate with each other without
any network.
And we can also say API is a code written by someone else and we are using that code in our
application to use that functionality.
Here are some Realistic API examples which we are using in our daily life:
Google API, Amazon advertising API,Twitter Api,YouTube API etc.

//Asked in interview
2-What are the main differences between API and Web-service?
An API is an interface that enables two applications to communicate with each other., while a
web service is a network-based resource that fulfills a specific task. Yes, there’s overlap
between the two: all web services are APIs, but not all APIs are web services.

All Web Services are API but not all API are Web Services . Web Services might not contain all
the specifications and can not perform all the tasks that API would perform .
Web Services only use three styles of use : REST , SOAP , XML RPC for communication
whereas API may be exposed in multiple ways like dll file, JAR file , XML over HTTP , JSON
over HTTP.
Web Services always need a network to operate whereas API does not need any network for
operation.

//Asked in interview
REST stands for Representational State Transfer. It is an architectural pattern used for
creating Web services.REST works with plain text, XML, HTML and JSON.
SOAP cannot make use of REST whereas REST can make use of SOAP.The interaction
is made through HTTP protocol in REST API.
The HTTP methods used in REST are :
GET , PUT , POST , DELETE , Patch (Difference b/w them) //Asked in interview

//Asked in interview
What is REST API?
REST API is a set of functions used by developers to perform requests and receive responses.
The interaction is made through HTTP protocol in REST API.

//Asked in interview
4-What is API Testing?
API Testing is a kind of software testing which determines if the developed API meets the
expectations regarding functionality,reliability,performance and security of the application.

//Asked in interview
5-What are the advantages of API Testing?
a-Test the core functionality
b-Time Effective
c-Fast Response
d-Language Independent

3-What are some Architectural styles for creating a Web API?


HTTP for client server communication
XML/JSON as a formatting language
Simple URI as a address for the service
Stateless communication

6-What are Some common Protocols Used in API Testing?


a- HTTP (Hypertext Transfer Protocol)
b-JMS (Java Message service)-->
c-SOAP (Simple Object Access Protocol)
d-REST (Representational State Transfer)
e-UDDI (Universal , Description , Discovery and Integration)-->XML Based Standard for
describing , Publishing and finding Web services.

//Asked in interview
7-What are the principles of API test design?
a-Setup
b-Execution
c-Verifying
d-Reporting
e-Clean-Up
//Asked in interview
8- What must be checked When performing API Testing?
a-Accuracy of data
b-HTTP Status Codes
c-Error code in case of API returns
d-Schema Validations
e-Data Type, validations ,completeness
f-Autoriation checks
g-Implementation of response timeout

9- What tools could be used for API Testing?


a-Postman
b-Katalon Studio
c-SoapUi-Pro
d-Tosca

//Asked in interview

HTTP VERBS/Methods
There are 4 basic HTTP verbs we use in requests to interact with resources in a REST system:

● GET — retrieve a specific resource (by id) or a collection of resources


● POST — create a new resource
● PUT — update a specific resource (by id)
● DELETE — remove a specific resource by id

For each HTTP verb, there are expected status codes a server should return upon success:

● GET — return 200 (OK)


● POST — return 201 (CREATED)
● PUT — return 200 (OK)
● DELETE — return 204 (NO CONTENT) If the operation fails, return the most specific
status code possible corresponding to the problem that was encountered.
Status Code Meaning

200 (OK) This is the standard response for successful HTTP requests.

201 (CREATED) This is the standard response for an HTTP request that resulted in
an item being successfully created.

202 (ACCEPTED) The request has been accepted for processing but the processing
has not been completed.

204 (NO CONTENT) This is the standard response for successful HTTP requests, where
nothing is being returned in the response body

400 (BAD REQUEST) The request cannot be processed because of bad request syntax,
excessive size, or another client error.

401 (UNAUTHORIZED) The request did not include an authentication token or the
authentication token expired.

402 (NON STANDARD Reserved for future


CLIENT ERROR) Ex:- The request can not be processed until the client makes a
payment.

.403 (FORBIDDEN) The client does not have permission to access this resource.

404 (NOT FOUND) The requested resource was not found.

405 (METHOD NOT The HTTP method in the request was not supported by the
ALLOWED) resource.

406 (NOT The server can not produce a response matching in the list of
ACCEPTABLE CLIENT accepted values.
ERROR)

407 (PROXY
AUTHENTICATION
REQUIRED CLIENT
ERROR)

408 (REQUEST
TIMEOUT RESPONSE)

409 (CONFLICT) The request can not be processed due to a conflict


500 (INTERNAL The request was not completed due to an internal error on the
SERVER ERROR) server.

501 (NOT The server did not recognise the requested method and is
IMPLEMENTED incapable of supporting it.
SERVER ERROR)

502 (BAD GATEWAY The server , while acting as a gateway or proxy , received an
SERVER ERROR) invalid response.

503 (SERVICE The server is currently unable to handle the request due to
UNAVAILABLE) temporary overloading or maintenance of the server.

10- What is REST?


Representational state transfer (REST) is a software architectural style that defines a set of
constraints to be used for creating Web services. Web services that conform to the REST
architectural style, called RESTful Web services
The six constraints are:

● Uniform Interface
● Stateless
● Cacheable
● Client-Server
● Layered System
● Code on Demand (optional)

REST stands for Representational State Transfer. It is an architectural pattern used for
creating Web services.REST works with plain text, XML, HTML and JSON.
SOAP cannot make use of REST whereas REST can make use of SOAP.The interaction
is made through HTTP protocol in REST API.
The HTTP methods used in REST are :
GET , PUT , POST , DELETE

//Asked in interview
11- What is SOAP ?
The abbreviation of SOAP is Simple Object Access Protocol . It is a message protocol
that allows two applications to communicate. SOAP only works with XML formats .
There are three components of web service:

SOAP-- Simple Object Access Protocol (Message Protocol)


WSDL-- Web Service Detail Language
UDDI-- Universal Description Discovery and Integration

WebServices works by the help of:


XML - to tag the data
SOAP - to transfer the data
WSDL - to describe the availability of service

//Asked in interview
12- Difference between REST and SOAP :
SOAP stands for Simple Object Access Protocol whereas REST stands for
Representational State Transfer. SOAP is a protocol whereas REST is an architectural
pattern. SOAP only works with XML formats whereas REST works with plain text, XML,
HTML and JSON. SOAP cannot make use of REST whereas REST can make use of
SOAP.

//Asked in interview
13- What is Postman ?
Postman is an API client and it is used to develop , test , share and document API’s.

//Asked in interview
14- What are Postman Collections?
Postman Collections are a group of saved requests you can organize into folders.

15- Why do you use Collections instead of History?


Every request you send in Postman appears under the History tab of the sidebar. On a
small scale, reusing requests through the history section is convenient. However, as
your Postman usage scales, it can be time consuming to find a particular request in
your history. Instead of combing through your history section, you can save all your
requests as a group for easier access.

16- What are Postman workspaces?


Postman workspaces allow you to organize and collaborate on API projects with your
team. Within each workspace you can share APIs, collections, environments, and other
components of your work in Postman.
//Asked in interview
17- What is Authentication & Authorization ?
In simple terms, authentication is the process of verifying who a user is, while
authorization is the process of verifying what they have access to.

18- Specify Authorization details?


There are several types of Authorization available in Postman :
● Inheriting Auth : By default, requests inside the collection or folder will inherit
auth from the parent, which means that they'll use the same auth that you've
specified at the folder or collection level.

● No Auth : If your request does not require authorization, select No Auth from the
Authorization tab Type dropdown list so that Postman will not attempt to send
authorization details with a request
● API Key : With API key auth, you send a key-value pair to the API either in the
request headers or query parameters.

● Bearer Token : Bearer tokens allow requests to authenticate using an access key,
such as a JSON Web Token (JWT). The token is a text string, included in the
request header.

● Basic Auth : Basic authentication involves sending a verified username and


password with your request.
In the request Headers, the Authorization header is going to pass the API a
Base64 encoded string representing the username and password values.

19- What are Variables in Postman?


A variable is a symbolic representation of data that allows you to access a value
wherever you need it, without having to enter it manually. This can be useful especially if
you are using the same values in multiple places. Variables make your requests more
flexible and readable.
Variables allows you to store and reuse values in your request and script. Using
variables increases your ability to work efficiently.

20- What do you understand by Variable Scopes in Postman?


Postman supports following Variable Scope :
● Global
● Collection
● Environment
● Data
● Local

If a variable with the same name is declared in two different scopes, the value stored in
the variable with the narrowest scope will be used—for example if there is a global and a
local variable both named “Username”, the local value will be used when the request
runs.

● Global Variables allows you access data between Collections , Environment ,


request and Scripts . Global variables are available throughout workspaces.

● Collection Variables are available throughout the requests in a collection and are
independent of Environments so do not change based on the selected
environments.
Collection Variables are suitable if you are using only one Environment.

● Environment Variables allows you to make your processing to different


environments. For ex- Local Development , Testing or Production.
Only one environment can be active at a time.
If you have only one environment using Collection Variable can be more effective.

● Data Variables come from external CSV and JSON files to define data sets you
can use when running collections via Newman or the Collection Runner.

21- Define variables in scripts


Use pm.globals to define a global variable
pm.globals.set(“Variable Key” , “Variable Value”);
Example :
pm.globals.set(“AccessToken” , “U56dggc”);
Or
Var JsonData = json.parse(ResponseBody);
Var AccessToken = JsonData.access_token;
pm.globals.set(“AccessToken” , AccessToken );

Use pm.CollectionVariables to define a Collection variable


pm.CollectionVariables.set(“AccessToken” , AccessToken);

Use pm.environment to define Environment Variable


pm.environment.set(“AccessToken” , AccessToken);

You can use Unset to remove a variable

pm.environment.unset(“AccessToken” , AccessToken);
Use pm.variables to define a Local variable
pm.variables.set(“AccessToken” , “usgd56”);

You can use “pm.variables.get” to get the variable value

console.log(pm.variables.get("variable_key"));

22- What is Visualizing Responses in postman?


Postman provides a Programmable way to visualize your request responses.

var template = `
<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
</tr>

{{#each response}}
<tr>
<td>{{name}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json()
});

You might also like