Wednesday 30 March 2022

API

 

API

API means Application Programming Interface

API is also called as Web Services.

Types of applications

  •         Standalone application
  •              Client server

Standalone application

  •       This type of application does not require internet.
  •          No server required
  •          No browser
  •         Single user
  •          Ex: Notepad, paint, calculator, MS Office, Browser

Client server

Client server requires internet, server, and bowser to access it. Multiple users can use client server. 

  • Client server 
  • Web application

Client server

Client server like WhatsApp, Telegram app etc.

Every client has its own server.

Client server requires client software to access it.

Example:

When we sent HI from client software (like WhatsApp), this client software will send request to software server (where source code present) where send source will execute and sent it back request to the client software that he can send the message.

Web application

Web application like Facebook, Gmail etc.

Web application require browser to access server.

Example

When we access a URL using browser like chrome, Firefox, etc., this Facebook URL is used to get request from Facebook server where Facebook server will executed login page code (.java file) and returns response to open Facebook login page in browser.

Introduction to web application

Web application requires browser to communicate with the server.

Server

It is a computer which will give access to communicate with web server and app server.

Every server also have RAM, HDD, OS (ex: 256GB RAM, 1000TD HDD, Windows 11)

It consists of two sub servers

  1. Web server
  2. App server/ Web application

Web server

Web server consists of ‘.html’ code which is used to access the ‘.java file’ through a communicator ‘servlet’.

App server

It consists of ‘.java’ code of the application which is used to execute the program.

Servlet

Servlet is also used for mapping between HTML and java files..

JDBC

JDBC stands for Java Database connectivity

It is used to connect java object with the database

Layers of Web server

  1. Presentation Layer
  2. Business Layer 
  3. Database Layer

Presentation layer consists of Web Server i.e. ‘.html’ code.

Business layer consists of ‘.java’ code.

Browser

·         Browser is a Standalone application used to access any web application via URL over the network.
·         Brower understands HTML, CSS, JavaScript
·         Browser makes use of http protocol. Hence it always send http request and receive http response.
·         Example: Mozilla, Chrome, Firefox, Edge, Safari, Internet explorer etc.,

Web Server

·         It is an application which runs on any operating system.
·         As the name implies the web server “Serves the response to the browser based on the request”.
·         Web server receives the request from the browser, communicates with the app server and gives back (or provide) the response to the browser.
·         Example:         Apache Tomcat, JBOSS, Web Sphere, Glass fish etc.

App Server/ Web Application

Collection of web resources within the web application is called as App Server.

There are two types of Web Resources

1.      Static Web Resources

2.      Dynamic Web Resources

Static Web Resources

Response generated even before the request is sent is called as Static web resource.

Ex: Wikipedia (coke)

Any web application which consists of only static resources is called as Static web application.

Note

To develop Static Web Application only HTML is enough.

Dynamic Web Resources

Response generated at the time of request is called as Dynamic web resources.

Ex: Internet Banking, (biryani)

If any web application contains at least one dynamic web resource it is termed as dynamic web application

Note

To develop Dynamic Web Application we use Servlet, Spring Boot (Automation frame work), etc.

Database

It is a type of software which is used to store data in the form of tables.

Ex: Oracle, My SQL, No SQL, Sybase, Mongo DB etc.

JDBC

JDBC stands for Java Data Base Connectivity.

It is used to connect java object with the database

It is a collection of Java API’s.

Servlet

It is a collection of J2EE (Advanced Java) API’s which is used to develop dynamic web application.

It is also used for mapping between HTML and java files.

Layers of Web Application

1.      Presentation Layer      -           contains HTML codes
2.      Business Layer                        -           contains Java code (Business logic/ Source code/ Web                                                         resources)
3.      Database Layer                       -           contains Data in the form of tables

Web URL

  • Web Uniform resource locator (URL) is used to identify specific web resource within the web application. 
  • Every application will have a unique address in the form of URL. 
  • Maximum number of characters in a Web URL is 200.

Syntax

Protocol: //Domain Name: Port number/ Resource Path? Query String # fragment Id

Protocol

  • When one application wants to exchange information with another application, there needs to be a common language which both the applications understand, hence we use protocol.
  • Protocol acts as a common language between two applications (in our case browser and server). 
  • It is a set of rules or instructions. 
  • Protocol is optional information in the web URL.

Types of Protocol 

  1. HTTP    -           Hyper Text Transfer Protocol 
  2. HTTPS -           Hyper Text Transfer Protocol Secured 
  3. SMTP   -           Simple Mail Transfer Protocol 
  4. FTP      -           File Transfer Protocol

Domain Name

It is used to identify specific computer/ server with in a network.

Domain name can be either computer name or IP address.

It is mandatory information present in the web URL.

Port number

It is used to identify specific application within a computer.

It is optional information present in the web URL.

Ex:      

 

Web logic

JBOSS

http

8080

80

https

8443

443

Resource Path

It is used to identify specific web resources within a web application.

It is optional information present in the web URL.

Query string

Query string always brings with ‘?’. It is always return using name = value pair.

We can have any number of name value pair separated by ‘&’.

Fragment Id

It is used to identify specific fragment or section.

Types of languages

  1.           Development language                      -           C, C++, C#, Java, Ruby
  2.           Scripting Language (Validate)            -           Python(Modules), JavaScript (angular JS, React JS),                                                  Visual basics, Shell script
  3.           Other Language                                  -           XML, JSON, XSD, DTD, HTML

XML

  •         XML means Extensible Mark-up Language.
  •      XML is a mark-up language used to store and transport the data between two applications.
  •         XML is an extension of HTML.
  •      It is a strictly typed language and hence case sensitive. 
  •      XML is platform/ language/ technology independent. 
  •      XML is a collection of user defined or customized tags
  •      In XML tags are also referred as elements
  •      XML follows Tree structure.

XML structure

<root>

            <child>

                        <subchild>

 

                        </subchild>

            </child>

</root>

Ex:

<StudentDetails>

            <Name> Sai </Name>

            <DOB> 29-12-95 </DOB>

            <Ph> 8247802033 </Ph>

            <Gender> Male </Gender>

</StudentDetails>

 

        XML follows Tree structure 

  •         It consists of one root element which is a parent of all the child and sub-child elements.
  •         XML tags or elements have to be properly nested or looped. 
  •         They cannot contain spaces. 
  •         They should always begin with a letter or an underscore ‘_’.

XML attributes and elements

Anything which includes start tag, value and end tag is collectively called as one element.

Any data which is declared in the start tag of an element is called as Attributes.

Attributes must be written always in Name = “value” pair.

Ex-1:

<student>

            <Name> Sai </Name>           

            <sal>            </sal>

</student>

Ex-2:

<student Name =” ”>

            <sal>                </sal>

</student>

  •          In example1 name is written as an element.
  •          In example2 name is written as Attribute.

XML entity references

Some characters in XML has a special meaning. For example ‘<’ is used to denote the start tag of an element. Hence we use XML entity references.

< 

&lt;

 >

&gt;

!

&quot;

&apos;

&

&amp;

Ex: <emp> sal<1000 </emp>

 


 

XML Parser

  • JAXB is a parser tool used to convert java to XML and vice versa.
  • Requester is a parser tool used to convert python to XML and vice versa.
  • The process of converting java to XML is called as Serialization/ Marshalling.
  • The process of converting XML to java is called as De-serialization/ Un-Marshalling.

JSON

  • JSON stands for JavaScript Object Notation.
  • It is used to store and transport the data between two applications.
  • JSON is a very light weight language. (Name: value pair)
  • JSON support various datatype.
  • JSON is an extension of JavaScript. Hence it looks similar to JavaScript.
  • JSON is very very popular.
  • JSON data can be parsed very easily.
  • JSON is supported by most of the browsers.

REST – Representation State Transfer

JSON structure

{

  “name1”: value1,

 “name2”: value2

}

Example

{

 “name”: “sai”,

 “age”:

}

Note

·         JSON follows MAP structure.

·         JSON data is written using name: value pair. Name should be always enclosed within double quotes and the value depends on the datatype.

Each name: value pair must be separated using coma ‘,’.

·         Curly brasses ‘{}’ are used to create an object.

·         Square brasses ‘[]’ are used to create an array.

JSON Parser

·         Jacson/ Jersy/ Jacsrc are the parser tools used to convert java to JSON and vice versa.

·         Requester is a parser tool used to convert python to JSON and vice versa.

·         The process of converting java to JSON is called as Serialisation/ Marshalling.

·         The process of converting JSON to java is called as De-serialisation/ Un-Marshalling.

JSON datatype

In JSON the values must be one of the following datatypes.
1.      String
2.      Number
3.      Boolean
4.      Null
5.      Array
6.      Object
7.      Object Array
·         String values must be written using double quotes (“ “).
·         Number can be any integer or a decimal.
·         Boolean is either true or false.
·         Null values are always null.
·         Array values must be enclosed with square brasses.

Different between XML and JSON

JSON

XML

  1. Java script object notation
  2. JSON data has a datatype, light weight.
  3. JSON types: String, number, array, Boolean, null, object.
  4. Data is readily accessible as JSON objects.
  5. JSON is supported by most browsers.
  6. Retrieving values is easy.
  7. A fully automated way of deserialization / serialization java script.
  8. It supports only UTF -8 encoding.
  9.  If doesn’t support comments.
  10. JSON files are easy to read as compared to SML.
  11. It is less secured.

  1. Extensible Mark-up Language
  2. XML data is type less.
  3. All XML data should be string.
  4. XML data needs to be parsed.
  5. Cross – browser XML parsing can be tricky.
  6. Retrieving value is difficult.
  7. Developers have to write java script code to serialize/ de-serialize from XML.
  8. It supports various encoding.
  9. It supports comments.
  10. XML documents are relatively more difficult to read and interpret.
  11. It is more secure than JSON.


Service Oriented Architecture (SOA)

 

Presentation layer

 

Business layer

 

Database

 

GUI

 

 

Source Code

 

 

 

Data

 

 

Functional testing

Manual

Automation

 

API Testing

1.WBT/ Unit testing

2.Web service testing

a. SOAP web service testing.

b. REST web service testing

 

Database testing

ETL (Extract/ Transform / Load)

 

API Testing

Testing the interface between two applications with respect to functionality, reliability, performance and security is called as API testing.
(Or) Testing the application in business layer is called as API testing.
(Or) Testing the application without the help of browser.

Unit Testing/ WBT

Testing the application in business layer (source code) with the help of another program is called as WBT/ Unit testing.
(Or) Testing the untouched source of a program is called Unit testing.

Web Service

Web service is a mechanism where two applications exchange information with each other irrespective of their underline technology.

Web service helps two applications exchange information without sharing the source code and the database data.

All web services are API, all API’s are not the web services.

Note

All web services are exposed via API.

Why Web Service Testing?

Web service testing is necessary because to check that all the API’s exposed or working as expected with respect to performance, reliability and security.
Web service provider has to do the web service testing.
Testing the request and response between two applications is called Web Service testing.

SOAP web service testing

What is SOAP?

SOAP stands for Simple Object Access Protocol.
It is an XML based protocol used to exchange information between two applications.

What is SOAP web service testing?

When two applications exchange information with each other which is based on XML using SOAP protocol, testing those request and response is called as SOAP web service testing.
(or)
Testing the request and response between two applications which is based on XML using SOAP protocol is called as SOAP web services testing.
·         All SOAP web services API are exposed via ‘.WSDL’ files.
·         WSDL stands for web service description language which is used to identify the location of the service.
·         All WSDL files has to be registration in UDDI
·         UDDI stands for Universal Description, Discovery, Integration.
·         If is a repository which is used for publishing, describing and finding web services.

SOAP web service testing tools

1.      SOAP UI
2.      SOAP SONAR
3.      WIZDL
4.      SOA TEST
5.      READY- API
6.      Test maker

REST web service testing

Testing the request and response between two application which is based on JSON, XML, HTML, JavaScript, text.
REST web service API’s are exposed via URI (User Response Identifier)

What is REST?

  • REST stands for Representational State Transfer.
  • It is an architectural style.
  • It is used to represent the state of the request.

REST web service testing tools

1.      Postman
2.      Rest Assured
3.      Rest client
4.      Ready API
5.      Karate
6.      Katalon

Difference between SOAP and REST web services

SOAP

REST

  1. Simple Object Access Protocol
  2. SOAP is a protocol
  3. SOAP is designed using too much of standards.
  4. SOAP API’s are exposed via .WSDL files.
  5. SOAP permits XML formats only.
  6.  SOAP cannot use REST since it is a protocol.
  7. SOAP defines its own security.
  8. SOAP is less preferred than REST.

1. Representational State Transfer

2. REST is an Architectural Style.

3. REST does not define too much standards.

 

4. REST API’s are exposed via URI.

5. REST permits JSON, XML, HTML, JavaScript, and test.

6. REST can use SOAP as well since it is a concept.

7. We have to inherit few security measures like Bearer token and Oauth.

8. REST is more preferred than SOAP.


Advantages of web services

1.      Web service interoperability (Platform / language/ Technology)
2.      Loosely coupled (changes done in one application will not have an impact on unrelated areas)
3.      No need of reinventing the wheel
4.      Business opportunity (ex: Swiggy, zomato, gobibo, ola)
5.      Service reuse (The service can be reused any number of times)

Http structure

 

http request

 

http response

 

 

Header

HTTP method

Web URL

Content type

Cookies

           

            M

Status code

Response time

Content- type

Cookies

 

Header

Body

Form –data

 

Actual – data

Body

 

Http method

Http method is mandatory information present in the header of http request.
It is used to specify the type of operation performed on the server.

POST

Use to create a resource

GET

Use to read the resource

PUT

Used for complete updation of the resource

PATCH

Used for partial updation

DELETE

Use to delete the resource

 

Content- type

It is used to specify the language, use to send the request.

Ex

  • Application/ JSON
  • Application/ XML
  • Application/ text
  • Application/ HTML

Cookies

It is the additional information.

Status code

It is used to specify the status of the request.
100 – Continue
200 – Successful
300 – Re-direction
400 – Client side server
500 – Server side error

HTTP status codes

Level 200 (Success)

 

Level 400

 

Level 500

200 : Ok

201 : Created

203 : Non-Authoritative             information

204 : No content

 

400 : Bad request

401 : Unauthorized

403 : Forbidden

404 : Not found

409 : Conflict

 

500 : Internal Server error

501 : Not Implemented

502 : Bad Gateway

503 : Service Unavailable

504 : Gateway timeout

599 : Network timeout

Response time

Total time taken to send the request, process the request and given back the response is called Response time.

Actual- data

If is the actual response provided by the server.

From –data

Data collected from browser to the server is called From-date.

Ex: Browser sending code details to the server.

Postman

Postman is a API client tool.

API Development team

API Testing team


Monitor API

Publish API document

Mock

Documentation


GUI

Open source

Easy to send request.

Snippets for validation

Collections ( end – to –end )

Command line execution using Newman

Easily integration with Jenkins.

Pre-Requirement for API testing

1.      Knowledge on client server architecture
2.      Knowledge on http request and http response properties.
3.      Knowledge on XML/JSON
4.      Basic knowledge on Database
5.      CURD
6.      API document/ API functional specification
7.      Knowledge on API testing tools
                    a.      Postman (Manual)
                    b.      Rest Assured (Automation)
8.      API testing case (+ve and -Ve)
9.      List of URI (Uniform Resource Interface)


SQL & PySpark Comparison

  SQL & PySpark Comparison Consept SQL PySpark Select SELECT column(s) From table SELECT * FROM table; df.select("column(s)") ...