Skipping certain API results
Introduction
In this lesson we will look at the following lesson outcomes:
- Inspecting the results of API calls.
- Skipping certain objects when looping over an array of objects.
- Introduction to postman.
Summative pre-assessment
View Survey
Postman
Postman is a powerful API development tool that allows developers to test, debug, and document REST APIs. It provides an intuitive interface for sending HTTP requests and viewing response data, making it easier for developers to work with APIs. It is an alternative to using RapidApi.
With Postman, developers can easily send requests to APIs, inspect the response data, and modify the request parameters. They can also store collections of requests for later use, automate API testing, and generate API documentation. Additionally, Postman provides features for managing API environments, sharing collections and requests with others, and integrating with other API development tools.
Postman is widely used by API developers and testers, as it makes it easy to test and develop APIs, and is available as a web app and as a native app for Windows, macOS, and Linux.
Download Postman and install it on your computer.
Inspecting the results of API calls
When making API calls, the most important thing to do is to inspect the JSON that the call returns.
You can’t make assumptions about what the JSON will contain and what properties you can access.
You can use a simple console.log or software like Postman.
View Video
Code from the video.
Skipping certain results
Sometimes you will want to ignore certain objects in an array. Perhaps they are missing specific properties, or the properties have useless values.
We can do this using the continue keyword inside a for loop.
continue causes the loop not to execute the code in its current iteration and jumps to the next iteration.
Like break, continue cannot be used inside a forEach function.
- break - exit the loop entirely.
- continue - skip this particular iteration of the loop.
for (let i = 0; i < array.length; i++) {
if (array[i].property < condition) {
// if condition is met, skip this iteration
continue;
}
doSomething(array[i]);
}
View Video
Code from the video.
Lesson Task
Brief
There are practise questions in the master branch of this repo.
Attempt to answer the questions before checking them against the answers branch of the repo.