I want to get more than 10 results. I set the offset to 50 so I can get 50 results but it still returns only 10.
I am using angular.
The documentation also says “use the offset parameter to offset results in multiple API calls”.
How do I make multiple API calls?
This is what my code looks like:
private httpHeaders: HttpHeaders = new HttpHeaders({
‘X-RapidAPI-Key’: ‘my-key’,
‘X-RapidAPI-Host’: ‘recipe-by-api-ninjas.p.rapidapi.com’
});
public searchText: string = '';
public getRecipes(): void {
let httpParams: HttpParams = new HttpParams().set('query', this.searchText);
httpParams.set('offset', 50);
this.http
.get<any>(`https://recipe-by-api-ninjas.p.rapidapi.com/v1/recipe`, {
headers: this.httpHeaders,
params: httpParams
})
.subscribe(data => {
console.log(data);
});
}
Partecipa alla discussione - aggiungi un commento di seguito:
Hi calorieninjas!
Thank you for your response but I am still getting the same 10 results:
Here is my code when I make multiple api calls. I set the offset to 0 then to 10 but still get the same results:
let httpParams: HttpParams = new HttpParams().set(‘query’, ‘chicken’);
The offset parameter does not change the maximum number of results returned (which is 10), it just offsets them. For example, if a query has 50 total results, you can set offset to 0 for first 10 results, set the offset to 10 for results 10-20, and so on.
By ‘making multiple API calls’, just make multiple http.get requests with different offsets.
Cheers