Filter Response

Learn how to filer responses of the REST Countries API

The REST Countries API allows us to specify the output fields of a request made to an API endpoint. This can be especially useful when working with large datasets because it allows us to narrow down the results and focus on the most relevant information. For instance, if we are querying the REST Countries API database and only need to see a few specific fields, we can specify which fields we want to include in the response of our request. This can help to streamline our work by reducing the amount of data we need to process, making it easier to find the information we need.

We can specify the required fields in the REST Countries API request by using the fields parameter. We can append this query parameter with the URLs of the endpoints discussed earlier to filter the response.

Here are some examples of how to specify the required fields. In these examples, we will specify the fields and check the effect on the response.

Filter a single field

In this example, we’ll only specify a single field to be returned in the response. We’ll use the URL of the All endpoint, which returns the information about all available countries. The URL for this endpoint is https://restcountries.com/v3/all. We’ll append fields=name as a query parameter with this URL to get only the name field in the response.

Click the “Run” button to fetch the specified field.

Get hands-on with 1400+ tech skills courses.