Chaining Requests?

So im new to using k6 and load testing in general. From what I can tell it seems like this tool is geared towards hitting one endpoint a lot with various iterations OR batching a lot of parallel calls at once (via the batch() function)

However I am curious IF and what the best practice is for stepping through or chaining endpoints. IE: endpoint A is called and we use the response (such as a unique id) for endpoint B and so on.

Obviously you probably I imagine lose a bit of performance potential doing this, but it may tackle common scenarios?

FWIW im strictly talking about API testing and not the “browser” testing.

Hi @mercfh

Welcome to the community forum :wave:

You can get the results of one request, and use the data for the following even if not browser testing. You can find an example in the k6 docs, under “data correlation”. And another example in k6-learn.

It’s true that we showcase how to extract values from html which looks more browser-oriented. However, it does not have to be for websites/browser testing. You can use data correlation also for API endpoints, if the answer comes in the response.

E.g. if the data you need to correlate comes in the response headers, you could use the Reseponse.header object. Or, as another example, you can use Response.json( [selector] ) and select the values you need if the response is in JSON format (more typical in REST APIs).

I hope this helps. If you still have doubts kindly share your (sanitized) script example and details on how the values to chain responses appear in your case and we’ll try to help out.