Search code examples
iosnetwork-programmingrequest

iOS Marvel API: How to get all Characters


I'm coding a simple Objective-C app as a request for a school Project.

I have to use the Marvel API to retrieve all the Marvel Characters, ALL of them.

But there is a kind of limit in the API getting the characters, in the beginning I was thinking that there were different pages for the characters list, but than I couldn't find any reference to it. Than I saw a query parameter named limit: Limit the result set to the specified number of resources.

So I've decided to try with the limit parameter set at his max, 100, and it works, it gets 100 characters. But the characters in total are like 1000.

Without setting the parameter limit I get like 20 characters.

Here is the code I've done so far. I'm Using AFNetworking pod. Github link

Here is the API Doc

Please help me to figure it with is the logic to request all the 1000+ characters from the marvel API.


Solution

  • Sounds like the trick that you'll need to implement is to actually trigger several HTTP requests where the offset parameter is incremented based on the limit requested in the prior requests.

    It would look like this:

    • Request 1: Offset 0, Limit 100
    • Request 2: Offset 100, Limit 100
    • Request 3: Offset 200, Limit 100
    • Request 4: Offset 300, Limit 100
    • Request 5: Offset 400, Limit 100
    • Request 6: Offset 500, Limit 100
    • Request 7: Offset 600, Limit 100
    • Request 8: Offset 700, Limit 100
    • Request 9: Offset 800, Limit 100
    • Request 10: Offset 900, Limit 100