mock api for testing code example
Example 1: 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 2: when to use mock api
We can use mock API server during
development and testing when live
data is unavailable or not reliable.
While developers designing the API
we can use mock API's to work on.
Once end points are available we can
implement the endpoints to our test script.
I am using Postman for mocking API.
I create mock server with GET request
to postman-echo.com/get endpoint.
Example 3: 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
Example 4: what mock api
We can use mock API server during
development and testing when live
data is unavailable or not reliable.
While developers designing the API
we can use mock API's to work on.
Once end points are available we can
implement the endpoints to our test script.
I am using Postman for mocking API.
I create mock server with GET request
to postman-echo.com/get endpoint.