api for testing code example

Example 1: how do you do positive api testing

How I do positive testing in api, 
	- I send valid path and query parameters, 
	- valid headers, 
	- valid request body to valid url and verify that 
	- response status code is correct and 
	- response body is as expected
    
How I do negative testing in api,
	- I send invalid request parameters
	- or invalid headers
	- or invalid request json body and verify 
    that response status code is not 200 
	- and response body contains error message 
    (for example there are 100 employees numbered
    from 1 to 100 I send 101 as a parameter and I
    should be able see 404 Not Found 
    The requested resource was not found.)

Example 2: json placeholder

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => console.log(json))

Example 3: dummy api json

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://reqres.in/api/products/3", true);
xhr.onload = function(){
    console.log(xhr.responseText);
};
xhr.send();

Example 4: have you done api testing

I have worked on API testing in my project and I used
POSTMAN for manually testing and REST ASSURED
java LIBRARY for automation.
I used JDBC and it is a Java-based data access technology
used for Java database connectivity. It provides classes and
interfaces to connect or communicate Java application with
database.
JDBC API is a Java API that can access any kind of data
stored in a Relational Database. It enables Java programs to
execute SQL statements.

Example 5: api testing approach

Write suitable test cases for the APIs and use testing techniques 
like exploratory testing, boundary value analysis, positive and negative 
testing for understanding the functionality.

• Verify the calls with combination of two or more value added parameters.
• Define the scope and basic functionality of the API program.
• Define the accurate input parameters.
• Test case execution and comparison of the results with expected results.
• Determining API behavior under conditions like the connection with files,
etc.

- There are different types of output observed of an API also:

The main consideration is returning correct results under any type of 
conditions. Mainly, the output or results observed of an API are divided 
into three sections as follows:
• Returning the result status values as ‘Pass’ or ‘Fail’.
• Result as data or any specific information.
• An event where the call to any API function will initiate the call to 
another API function

Example 6: dummy api

React Fakers is a collection of dummy data from the most popular dummy data
providers such as Json Place Holder, Faker, Pokemon, etc, 
for application development testing.

npm i react-fakers | yarn add react-fakers

Tags:

Css Example