Api 01

You might also like

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

API Testing Course

By : Tarek Roshdy
Course Content
• Part I : API Basics
• Part 2 : API Testing using Postman
• Part 3 : Advanced Topics
PART I : API Basics
-What is an API?
-HTTP Basics
-XML & JSON
-SOAP & REST APIs
-Why API Testing
-API Testing Tools
What is an API ?
Letter Word Meaning
A Application Software that does a task
P Programming Program (p) that does the task in the application (A)
I Interface Place (I) to tell the program (p) to run

API is when you (interface) tell a computer (program) to run an (application)


What is an API ?
• Interface : From where are you telling the program to run?
• Program : What task is being done?
• Application : What software the program is running?
Practical Exercise

• Search for a popular website APIs


on the internet

• What do you notice ?


What happens in the API ?
1.Request
2.Program
3.Response
Practical Exercise

• Search for you name on Google


using the URL

• www.google.com/search?q=Yourname
Practical Exercise

• Try to search for Mohamed Salah in


google images

• We will send two parameters


– Name of the player
– The search method (isch)
Practical Exercise

1. Go to developer.ebay.com
2. Click on API explorer
3. Create a user
4. Search for an item
5. Try to order an item
What is a webservice ?

• Web = Internet
• Service = API
• Web service = API that goes through the
internet
• All webservices are APIs
• Not all APIs are webservices
Webservice?

• We use XML & JSON to format data


• We use SOAP, REST, XML/RPC to transfer that data
API Mashup
• API that is created from other APIs
• Example : Travelocity
HTTP Basics
What is HTTP?
• Hypertext Transfer Protocol
• It consists of 4 parts :
– Startline (mandatory)
– Headers
– Blank Line
– Body
Start Line
• Request :
– Version (1.1 or 2)
– Method (Get-Post-Put-Delete)
– Folder & Parameters
(/search?q=mohamedsalah)
Start Line
• Response:
– Version (1.1 or 2)
– Status Code
• 1xx (Informational): The request was received, continuing process
• 2xx (Successful): The request was successfully received, understood
and accepted
• 3xx (Redirection): Further action needs to be taken in order to
complete the request
• 4xx (Client Error): The request contains bad syntax or cannot be
fulfilled
• 5xx (Server Error): The server failed to fulfill an apparently valid
request
Headers
• Request :
– Host (www.google.com)
– Token (used in security)
Headers
• Response :
– Cookies
Blank Line
• Like its name states, it’s a blank line to
separate the header from the body
Body
• Request :
– Get (nothing in the body)
– Post (the data you provide, xml or json)
Body
• Response :
– What you requested
– HTML webpage
What is XML ?
What is XML?
• Extensive Mark-up Language
• A format we use to send the APIs
• Created by W3C (The same organization
created HTML)
• In XML, the terms in the tags don’t
mean anything
• In HTML, the terms mean something
What is XML?
• HTML is not Extensible (you can’t extend
it to mean something else)
• Browsers can understand XML

– HTTP Header Line : Content-Type: application/xml


– HTTP Body : XML
What is XML?
<shawerma>
<size>large</size>
<type>chicken</type>
<additions>
<add>towmea</add>
<add>tehena</add>
<add>mekhalel</add>
</additions>
</shawerma>
What is XML?
<Course>
<Category>Software Development</Category>
<Section>Software Testing</Section>
<Target audience>
<aud>students</aud>
<aud>Software Engineers</aud>
<aud>Junior Testers</aud>
</Target audience>
</Course>
Practical Exercise

1. Write your own XML in Notepad++


2. Save it as an XML file
3. Open it in your browser
4. Optional (try to create two courses
in the same file)
What is JSON?
What is JSON?
• Javascript Object Notation
• It’s the part of javascript that holds data
• JSON code is smaller than xml

• HTTP Header Line : Content-Type: application/json


• HTTP Body : json
What is JSON?
{"shawerma" :
{"size" : "large",
"type" : "chicken",
"additions" : ["Towmea", "Tehena", "extra cheese"]
}
}
What is JSON?
{“Course" :
{“Category" : “Software Development",
“Section" : “Software Testing",
“Target Audience" : [“Students", “Software
Engineers", “Junior Testers"]
}
}
What is JSON?
{ “shawerma” : [
{“size” : “large”,
“Additions” : [“towmea”, “Mekhalel”]
},
{“size” : “medium”,
“Additions” : [“Tehena”, “Batates”]
}
]
}
Practical Exercise

1. Write your own JSON in Notepad++


2. Save it as a JSON file
3. Open it in your browser
4. Optional (try to create two courses
in the same file)
Can you understand this ?
{"widget":
{ "debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"alignment": "center",
}
}}
Can you understand this ?

<widget>
<debug>on</debug>
<window title="Sample Konfabulator Widget">
<name>main_window</name>
<width>500</width>
<height>500</height>
</window>
<image src="Images/Sun.png" name="sun1">
<alignment>center</alignment>
</image>
<text data="Click Here" size="36" style="bold">
<name>text1</name>
<alignment>center</alignment>
</text>
</widget>
JSON VS. XML
JSON VS. XML
JSON VS. XML
XML JSON
Powerful Yes NO
Simple NO Yes
Developed 1997 2001
Popularity Down Up

There is no major difference, you need to understand them both


SOAP APIs
What is SOAP?
• Simple Object Access Protocol
• A protocol to access objects (APIs) in a
simple way (not very simple)
• It uses WSDL (Web service Description
Language)
What is SOAP?

• Start Line POST WSDL HTTP Version


• Header Line Content Type : text/xml
• Blank Line
• Body XML Envelope formed using WSDL
Practical Exercise

• Search Google for “WSDL example”

• Open any link and try to read its


content
REST APIs
What is REST?
• Representational State Transfer
• Rest is representational, the actual record is
not sent, a representation of the record is sent.
• Rest is Stateless
• IN SOAP, if the program stops (at the server), it
breaks down then we have a major issue. REST
waits until it works (Stateless)
• REST uses JSON
REST APIs

HTTP CRUD Idempotent Safety

Post Create No No

Get Read Yes Yes

Put Update/Replace Yes No

Patch Update/Modify No No

Delete Delete Yes No


Practical Exercise

• Open this link


http://www.webservicex.net/#/home
• Search for Egypt
• What do you notice ?
• Which method will be used to
access the data at this website
(get-post-put-patch-delete)
SOAP VS. REST APIs
SOAP VS. REST APIs
SOAP VS. REST APIs
Why API Testing ?
 Skills you need to be a good tester
 Source : 2018 State of Testing report
Why API Testing ?
 Most Popular Testing Types in Egypt
 Source : Egypt Software Testing Report 2019
Why API Testing ?
 Most Popular Testing Tools in Egypt
 Source : Egypt Software Testing Report 2019
Why API Testing ?
 Early Testing Saves Time & Money

You might also like