how does api testing work code example

Example 1: how to test rest api

First, I verify if each REST API end-point is working as
expected.
- I use POSTMAN for manual API testing and use
RESTASSURED library in Java for automation.
- I send GET, POST, PUT, DELETE type of requests and
verify response status code and response body.
- I also do positive/negative testing of API.


When I do positive testing,
I send
valid request parameters,
valid headers,
valid request json body to valid url and verify that
response status code is 200 and
Json response body data is as expected.
When I do negative testing,

I send
invalid request parameters,
or invalid headers,
or invalid request json body and verify
response status code is not 200.

and Json response body contains error message. (for example, there are 100
employees numbered from 1 to 100, I send 101 as an end-point and I should be
able see 404 Not Found. The requested resource was not found.

Example 2: 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