Sometimes you just want to limit your response a little bit!

In the previous tutorial, we have explained the fundamentals of filtering API responses, which allows you to request the exact data you need. However, sometimes the response can be rather large. In such cases, you can use our limiting feature. In this part of our tutorial, you will be able to limit your API responses.

What is limiting?

Limiting, as its name suggests, will limit the response you get from our API to a specific amount. Limiting your API responses can come in handy when you want to avoid big API responses. In this tutorial, we'll show you how limiting is used and why it may be handy for you. Let's go!

Create the request

In this tutorial, we will request all the fixtures from the 20/21 season from the Scottish Premiership (season id: 17141). As for the endpoint, we’ll go with season by id. Furthermore, as discussed in our includes tutorial, we’ll enrich the response with an include. In this case, we’ll use the include called fixtures

The below request will give you all the fixtures of the 20/21 season of the Scottish Premiership (season id: 17141).

The response is enormous. Therefore, we've copied a small snippet instead of the full response.{API_TOKEN}&include=fixtures

Evaluate the response

Your first thought is probably: ‘Wow that’s an enormous response’. This is because football seasons tend to have a large number of matches. In order, to make the response more legible we can introduce a limit.

Limit the response

By limiting the response, we mean that you can limit the number of results per page. Let’s say we want to limit the response to only five results per page. You still need to use the fixtures include, but now you can add :limit(X|X).

The first attribute (X) is the number of records per page, while the second (X) is the page currently browsed.

For example, if you want 5 fixtures per page and you want to browse the first page: &include=fixtures:limit(5|1){API_TOKEN}&include=fixtures:limit(5|1)

Now there are only five results per page! Moreover, you can simply replace the ‘1’ in (5|1) for a ‘2’, if you want to go to the second page. And just like that, you have successfully limited an API response!

Note that paginating through includes count towards your request limit

You’ve learnt how to filter and limit your response. Next up you will learn how to sort the API response.

Last updated