restautomated-testspostman

How can I run automated tests to check the average response time of a rest API?


I have a RESTful API that I would like to run some tests against at random moments of the day in order to check the average response time. I wasn't able to do this using Postman's Collection Runner. Is there another tool which allows me to do this, or maybe I'll have to write my own?


Solution

  • You can use services like Pingdom to retrieve calls from your API, or you can use softwares (commercial or opensource, is Zabbix still around?) to monitor your API, or (if you don't need many perks) you can write yourself a script that runs in a cronjob and saves the response time of your API in a txt file (or wherever you want) for further inspection.

    Here's a little example, in php, but you can easily adapt it to your fav. language.

    // I don't know how much will it take to run the API request
    set_time_limit(0)
    
    $start = microtime(true);
    
    $result = executeApiCall()
    
    $executionTime = microtime(true) - $start;
    
    storeExecutionTime($executionTime)
    
    function storeExecutionTime($time) {
       // store the data somewhere
    }