Reputation: 1747
using cypress i'm intercepting an API call and want to get how much the response time it took
cy.intercept("PATCH", "https://api.website.com/b2b2/**").as("myAPP")
cy.wait("@myAPP").then(({ request, response }) => {
expect(response.duration).to.be.lessThan(2000)// => expected undefined to be a number or a date
expect(response.statusCode).to.equal(200)
})
Upvotes: 0
Views: 72
Reputation: 19
there are many ways but You may try with
const fetch = require('node-fetch');
(async () => {
const startTime = Date.now();
const response = await fetch('https://api.example.com/data');
const data = await response.json();
const endTime = Date.now();
const responseTime = endTime - startTime;
console.log(`Response Time: ${responseTime} ms`);
})();
Open Postman. Send the API request. After the request is completed, Postman displays the response time in the bottom-right corner under the "Response" section.
Upvotes: 0
Reputation: 59
In JavaScript, you can measure how fast an API call is by using performance
API.
For example:
const start = performance.now();
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => {
const end = performance.now();
const responseTime = end - start;
console.log(`Response time: ${responseTime} milliseconds`);
});
Upvotes: 0