Get stats

GET {{mock_url}}/stats

RESPONSES

status: OK

{"welcome":"Welcome! Check out the 'data' object below to see the values returned by the API. Click **Visualize** to see the 'tutorial' data for this request in a more readable view.","data":{"won":9,"lost":3,"drew":4},"tutorial":{"title":"Running collections","intro":"This request returned some team stats—this time you'll add scripting to use with the collection runner.","steps":[{"note":"This is the data returned by the request:","raw_data":{"won":9,"lost":3,"drew":4}},{"note":"First add some test code to each of the three requests in this folder so that you can review them in the collection runner. You already had code in the `Get all players` request—make sure you save the request so that the collection runner uses that code. Add the same status code test you used earlier to the `Get specific player` **Tests** and **Save** the request. Do the same in this request if you like too.","js_code":["pm.test('Status code is 200', function () {","    pm.response.to.have.status(200); ","});"]},{"note":"Now add a slightly more complex test to this request (`Get stats`) to check that the array includes all of the required stats fields (remember to **Save** the request), then send it, check the **Test Results**, and come back here.","js_code":["pm.test('Stats include all fields', function () {","    var jsonData = pm.response.json().data;","    pm.expect(jsonData).to.have.all.keys('won', 'lost', 'drew');","});"]},{"note":"Earlier you added code to set a variable from response data, but you had to run the two requests in order manually—you can use the Postman collection runner to run sequences of request in a collection. In the app, click **Runner**, select the Student Training collection **and the `2. Scripting and Collection Runs` folder**, select the environment you used earlier, and run the collection. If you're on the web version of Postman, select the `2. Scripting and Collection Runs` folder on the left and click **Run**.","pic":"https://assets.postman.com/postman-docs/student-expert-runner-web.jpg"}],"next":[{"step":"You should see your test results output including passed and failed status. _Note that you can also use the **Console** at the bottom left to drill down into requests and responses._","pic":"https://assets.postman.com/postman-docs/student-expert-runner-output-web.jpg"},{"step":"Finally, you're going to use additional scripting to change the request execution order. In the **Tests** tab for the `Get specific player` request, add the following code. The `played` number is a random int between 0-1000, so the code sets Postman up to re-run the collection from the `Get all players` request however many times it takes to find a `played` value greater than 750. Check out where the `played` field appears in the response by opening **Body** \u003e **Pretty** in the request. **Save** the request.","js_code":["if(pm.response.json().data.played\u003c750) postman.setNextRequest('Get all players');"]},{"step":"With all of your requests saved, open the collection runner again, and click the run you ran earlier from the **Recent Runs** list. Click **Retry** to run your collection again—it might run a different number of times whenever you run it depending on how long it takes to hit that \u003e750 played value. Try clicking **Retry** a few times to see how it behaves differently each time (note that you only ran one iteration but built a loop workflow using `setNextRequest`—you can explicitly set the number of iterations when you set the run up instead of leaving it to chance like you did here).","pic":"https://assets.postman.com/postman-docs/student-expert-runner-result-web.jpg"},{"step":"You've worked through the Postman Student Expert training collection! 🤓😎🥳 To complete your training, open the final folder in the collection **3. Check Progress** \u0026gt; open the **Skill check** request, and hit **Send**. Complete the steps listed in the **Visualize** view until you get a success response."}]}}