It’s a dark and stormy night. You’ve been working on that last bit of code and an explosion rocks your living room. In walks Doctor Doom with a simple demand:
How many other “doctors” are in the Marvel universe?
Unless you’re Comic Book Guy and know this off the top of your head, you’re going to need a little help.. so with that, let me announce the PHP library for the Marvel API.
Overall, using the API isn’t a perfect experience but it provides a wealth of information in a mostly-consumable fashion. You can make individual requests to get all the information on your favorite Characters, Events, Creators, and even individual story lines. In a matter of minutes, you can retrieve all the information on all the variations of Spider-Man you can think of. Using the library, it really is only a few lines of code.
Unfortunately, you can’t search using the API. Unless you’re willing to iterate through results, you need to come up with exact matches. For example, “Doctor Doom” and “Doctor Doom (Ultimate)” are considered two totally separate characters with separate entries.
So back to our story..
There are really three steps to this problem. First, we need to connect to the service, then get a list of characters, and then figure out which are doctors.
This count statement gives us a total of eight doctors.. but remember that the API considered “Doctor Doom” and “Doctor Doom (Ultimate)” as two different characters. After we actually look at the names, we figure out there are actually only five doctors: Doom, Faustus, Octopus, Spectrum, and Strange.
If Doctor Doom ever comes knocking down your door, I hope this comes in handy. 😉
In the meantime, check out the Marvel API.