SlideShare a Scribd company logo
REST API TEST
By Anil Upadhyay
Test Case Creation
• Understanding the functionality of the API program and
clearly define the scope of the program
• Apply testing techniques such as equivalence classes,
boundary value analysis, and error guessing and write test
cases for the API
• Input Parameters for the API need to be planned and
defined appropriately
• Execute the test cases and compare expected and actual
results.
Basic Practice of API Testing
• Test cases should be grouped by test category
• On top of each test, you should include the declarations of the APIs being
called.
• Parameters selection should be explicitly mentioned in the test case itself
• Prioritize API function calls so that it will be easy for testers to test
• Each test case should be as self-contained and independent from
dependencies as possible
• Call sequencing should be performed and well planned
• To ensure complete test coverage, create test cases for all possible input
combinations of the API.
Automated Testing of APIs
using Java
• Plain Old Java Object (POJO)
• Serialisation & Deserialisation
• Rest-assured
• Any Java Assert Library
POJO
• Plain Old Java Object (POJO): Pojo in Java stands for Plain Old Java Object and they are
used for increasing the readability and re-usability of a program. They are normal java
objects, unbounded by special restrictions, other than the ones forced by the Java
Language Specification.
• In simpler terms, Pojo is defined as a pure data structure, containing the getter and setter
fields. It has the ability to override certain methods from Object or an interface such as
Serializable.
• A POJO must not :
• Extend pre-specified classes: Ex- public class Test extends javax.servlet.http.HttpServlet is
not considered to be a POJO class.
• Contain pre-specified annotations: Ex- @javax.persistence.Entity public class Test{..} is not
a pojo class.
• Implement prespecified interfaces: Ex- public class Test implements javax.ejb.EntityBean {
… } is not considered to be a POJO class.
Serialisation &
Deserialisation
• Serialisation is a mechanism of converting the state of an object into a byte stream. Deserialisation is the reverse process
where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
HTTP METHODS
• HTTP defines a set of request methods to indicate the
desired action to be performed for a given resource.
Although they can also be nouns, these request methods
are sometimes referred as HTTP verbs. Each of them
implements a different semantic, but some common
features are shared by a group of them: e.g. a request
method can be safe, idempotent, or cacheable.
• GET : The GET method requests a representation of the
specified resource. Requests using GET should only
retrieve data.
HTTP METHODS
• POST: The POST method is used to submit an entity to
the specified resource, often causing a change in state or
side effects on the server.
• PUT: The PUT method replaces all current
representations of the target resource with the request
payload.
• DELETE: The DELETE method deletes the specified
resource.
• PATCH: The PATCH method is used to apply partial
modifications to a resource.
HTTP HEADERS
• HTTP headers let the client and the server pass additional
information with an HTTP request or response. An HTTP
header consists of its case-insensitive name followed by a
colon (:), then by its value. Whitespace before the value is
ignored.
• Headers can be grouped according to their contexts:
• General headers apply to both requests and responses, but
with no relation to the data transmitted in the body.
• Request headers contain more information about the resource
to be fetched, or about the client requesting the resource.
HTTP HEADERS
• Response headers hold additional information about the
response, like its location or about the server providing it.
• Entity headers contain information about the body of the
resource, like its content length or MIME type.
IMPORTANT
HEADERS
• Authorization
• Contains the credentials to authenticate a user-agent with a
server.
• Connection
• Controls whether the network connection stays open after the
current transaction finishes.
• Keep-Alive
• Controls how long a persistent connection should stay open.
IMPORTANT
HEADERS
• Accept
• Informs the server about the types of data that can be sent back.
• Accept-Language
• Informs the server about the human language the server is expected to send back. This is a
hint and is not necessarily under the full control of the user: the server should always pay
attention not to override an explicit user choice (like selecting a language from a dropdown)
• Content-Length
• The size of the resource, in decimal number of bytes.
• Content-Type
• Indicates the media type of the resource.
• https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
The GET Method
• GET is used to request data from a specified resource.
• GET is one of the most common HTTP methods.
• GET requests can be cached
• GET requests remain in the browser history
• GET requests can be bookmarked
• GET requests should never be used when dealing with sensitive data
• GET requests have length restrictions
• GET requests are only used to request data (not modify)
The GET Method
Syntax
GET /index.html
The POST Method
• The HTTP POST method sends data to the server. The type of the
body of the request is indicated by the Content-Type header.
• The difference between PUT and POST is that PUT is idempotent:
calling it once or several times successively has the same effect
(that is no side effect), where successive identical POST may have
additional effects, like passing an order several times.POST
requests are never cached
• POST requests do not remain in the browser history
• POST requests cannot be bookmarked
• POST requests have no restrictions on data length
The POST Method
POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
field1=value1&field2=value2
The PUT Method
• The HTTP PUT request method creates a new resource or replaces a representation of the target
resource with the request payload.
• The difference between PUT and POST is that PUT is idempotent: calling it once or several times
successively has the same effect (that is no side effect), where successive identical POST may
have additional effects, like passing an order several times.
The DELETE Method
• The HTTP DELETE request method deletes the specified
resource.

More Related Content

PPSX
API Test Automation
PPTX
Rest assured
PDF
API Testing
PPTX
REST-API introduction for developers
PPTX
Understanding REST APIs in 5 Simple Steps
PPT
Understanding REST
PPTX
introduction about REST API
PDF
An Introduction To Automated API Testing
API Test Automation
Rest assured
API Testing
REST-API introduction for developers
Understanding REST APIs in 5 Simple Steps
Understanding REST
introduction about REST API
An Introduction To Automated API Testing

What's hot (20)

DOCX
Api testing bible using postman
PPTX
Rest assured
PDF
2015-StarWest presentation on REST-assured
PDF
Learn REST in 18 Slides
PPTX
Soap vs rest
PPT
Postman.ppt
PPTX
Api Testing
PPTX
ASP.NET Web API and HTTP Fundamentals
PPTX
POSTMAN.pptx
PDF
REST API and CRUD
PPTX
Spring boot Introduction
PPTX
API Testing Using REST Assured with TestNG
PPTX
Api testing
PPTX
Apache tomcat
PDF
Introduction to ReactJS
PPTX
Introduction to angular with a simple but complete project
PDF
Api Testing.pdf
PDF
What is REST API? REST API Concepts and Examples | Edureka
PDF
Hibernate Presentation
PPTX
REST & RESTful Web Services
Api testing bible using postman
Rest assured
2015-StarWest presentation on REST-assured
Learn REST in 18 Slides
Soap vs rest
Postman.ppt
Api Testing
ASP.NET Web API and HTTP Fundamentals
POSTMAN.pptx
REST API and CRUD
Spring boot Introduction
API Testing Using REST Assured with TestNG
Api testing
Apache tomcat
Introduction to ReactJS
Introduction to angular with a simple but complete project
Api Testing.pdf
What is REST API? REST API Concepts and Examples | Edureka
Hibernate Presentation
REST & RESTful Web Services
Ad

Similar to Rest API Testing (20)

PPTX
Rest APIs Training
PPTX
Rest WebAPI with OData
PPTX
Test Design and Automation for REST API
PPTX
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
PPTX
Pragmatic REST APIs
PDF
REST API Recommendations
PPT
Servlet.ppt
PPT
Servlet.ppt
PPT
Servlet1.ppt
PPT
Servlet (1) also contains code to create it.ppt
PDF
Api security-testing
PPT
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
PDF
Best Practices in Web Service Design
PPTX
Overview of REST - Raihan Ullah
PDF
Ch 3: Web Application Technologies
PDF
CNIT 129S: Ch 3: Web Application Technologies
PPTX
RESTful Services
PDF
CNIT 129S - Ch 3: Web Application Technologies
PPTX
PPTX
6 Months Industrial Training in Spring Framework
Rest APIs Training
Rest WebAPI with OData
Test Design and Automation for REST API
Ivan Katunov. Comaqa Spring 2018. Test Design and Automation for Rest API.
Pragmatic REST APIs
REST API Recommendations
Servlet.ppt
Servlet.ppt
Servlet1.ppt
Servlet (1) also contains code to create it.ppt
Api security-testing
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Best Practices in Web Service Design
Overview of REST - Raihan Ullah
Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
RESTful Services
CNIT 129S - Ch 3: Web Application Technologies
6 Months Industrial Training in Spring Framework
Ad

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
“AI and Expert System Decision Support & Business Intelligence Systems”
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
cuic standard and advanced reporting.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity

Rest API Testing

  • 1. REST API TEST By Anil Upadhyay
  • 2. Test Case Creation • Understanding the functionality of the API program and clearly define the scope of the program • Apply testing techniques such as equivalence classes, boundary value analysis, and error guessing and write test cases for the API • Input Parameters for the API need to be planned and defined appropriately • Execute the test cases and compare expected and actual results.
  • 3. Basic Practice of API Testing • Test cases should be grouped by test category • On top of each test, you should include the declarations of the APIs being called. • Parameters selection should be explicitly mentioned in the test case itself • Prioritize API function calls so that it will be easy for testers to test • Each test case should be as self-contained and independent from dependencies as possible • Call sequencing should be performed and well planned • To ensure complete test coverage, create test cases for all possible input combinations of the API.
  • 4. Automated Testing of APIs using Java • Plain Old Java Object (POJO) • Serialisation & Deserialisation • Rest-assured • Any Java Assert Library
  • 5. POJO • Plain Old Java Object (POJO): Pojo in Java stands for Plain Old Java Object and they are used for increasing the readability and re-usability of a program. They are normal java objects, unbounded by special restrictions, other than the ones forced by the Java Language Specification. • In simpler terms, Pojo is defined as a pure data structure, containing the getter and setter fields. It has the ability to override certain methods from Object or an interface such as Serializable. • A POJO must not : • Extend pre-specified classes: Ex- public class Test extends javax.servlet.http.HttpServlet is not considered to be a POJO class. • Contain pre-specified annotations: Ex- @javax.persistence.Entity public class Test{..} is not a pojo class. • Implement prespecified interfaces: Ex- public class Test implements javax.ejb.EntityBean { … } is not considered to be a POJO class.
  • 6. Serialisation & Deserialisation • Serialisation is a mechanism of converting the state of an object into a byte stream. Deserialisation is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
  • 7. HTTP METHODS • HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. Although they can also be nouns, these request methods are sometimes referred as HTTP verbs. Each of them implements a different semantic, but some common features are shared by a group of them: e.g. a request method can be safe, idempotent, or cacheable. • GET : The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
  • 8. HTTP METHODS • POST: The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. • PUT: The PUT method replaces all current representations of the target resource with the request payload. • DELETE: The DELETE method deletes the specified resource. • PATCH: The PATCH method is used to apply partial modifications to a resource.
  • 9. HTTP HEADERS • HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored. • Headers can be grouped according to their contexts: • General headers apply to both requests and responses, but with no relation to the data transmitted in the body. • Request headers contain more information about the resource to be fetched, or about the client requesting the resource.
  • 10. HTTP HEADERS • Response headers hold additional information about the response, like its location or about the server providing it. • Entity headers contain information about the body of the resource, like its content length or MIME type.
  • 11. IMPORTANT HEADERS • Authorization • Contains the credentials to authenticate a user-agent with a server. • Connection • Controls whether the network connection stays open after the current transaction finishes. • Keep-Alive • Controls how long a persistent connection should stay open.
  • 12. IMPORTANT HEADERS • Accept • Informs the server about the types of data that can be sent back. • Accept-Language • Informs the server about the human language the server is expected to send back. This is a hint and is not necessarily under the full control of the user: the server should always pay attention not to override an explicit user choice (like selecting a language from a dropdown) • Content-Length • The size of the resource, in decimal number of bytes. • Content-Type • Indicates the media type of the resource. • https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
  • 13. The GET Method • GET is used to request data from a specified resource. • GET is one of the most common HTTP methods. • GET requests can be cached • GET requests remain in the browser history • GET requests can be bookmarked • GET requests should never be used when dealing with sensitive data • GET requests have length restrictions • GET requests are only used to request data (not modify)
  • 15. The POST Method • The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header. • The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.POST requests are never cached • POST requests do not remain in the browser history • POST requests cannot be bookmarked • POST requests have no restrictions on data length
  • 16. The POST Method POST /test HTTP/1.1 Host: foo.example Content-Type: application/x-www-form-urlencoded Content-Length: 27 field1=value1&field2=value2
  • 17. The PUT Method • The HTTP PUT request method creates a new resource or replaces a representation of the target resource with the request payload. • The difference between PUT and POST is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.
  • 18. The DELETE Method • The HTTP DELETE request method deletes the specified resource.