Search code examples
restpostmanrest-client

Rest Client for multiple sequential requests


Is there a tool available for making rest calls to api endpoints. My task is to sequentially run a list of commands where one command uses some response of previous command and runs. I checked postman which allows me to run multiple requests simultaneously using collections but how can I use a response and use it for the next post request and Automate the whole process? Or is there any other tool which would help?


Solution

  • In postman You can set environment variables with the results and then use them in the next requests.

    Checkout out postman's docs. chaining requests

    Another way would be by using a simple javaScript in NodeJS. Ex: (get the first github user´s follower in 2 chained requests):

    const fetch = require('node-fetch');
    
    fetch('https://api.github.com/users/github')
        .then(function(gituhubUser) {
            return gituhubUser.json();
        })
        .then(function(gituhubUserJSON) {
            return fetch(gituhubUserJSON.followers_url)
        })
        .then(function(followers) {
            return followers.json();
        })
        .then(function(followersJSON) {
           console.log(followersJSON[0].login);
        })
        .catch(function(err) {
           console.log(err);
        });