0

In my PHP application, I input from the user the movies that he likes, and then I query the Topic API to retrieve details on each movie.

Is there a way to batch the calls so that I don't have to make multiple http requests? For eg., if the user enters 10 movie names, is it possible to make a single http request to retrieve information on all ten movies, or should I be making 10 API calls - one for each movie? The latter approach severely strains the speed of my application.

Ninja
  • 5,082
  • 6
  • 37
  • 59

2 Answers2

1

There are a few different possibilities that I see:

  1. You could just fire off multiple Topic API requests in parallel. There's no rule saying they have to be done sequentially. This would reduce the latency greatly.

  2. You could use a cache in front of Freebase to store recently fetched results locally. This is probably a good idea independent of anything else and would greatly reduce round-trip times for cached results.

  3. You could use the HTTP Batch facility offered by the Google APIs to make multiple requests at one. I'm not 100% sure it works with the Topic API, but I know it works with MQLread, so perhaps you convert to using that.

  4. The Search API can return results in much the same form as the Topic API and it can take multiple IDs, so you could do something along the lines of: https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28any+mid:/m/0dtfn%20mid:/m/0ddjy%29&output=(all:/film)&indent=true

Tom Morris
  • 10,490
  • 32
  • 53
  • (a) I guess MQLread is not a good option, since it's legacy and requires an exact text match. (b) I am using the Search API with the output parameter - this means I don't need to call the Topic API at all. That is good, since it halves the number of http requests. (c) I don't know the MIDs of the movies - so (4) in your answer isn't an option. (d) Caching locally is a good option, will try that (e) Is it possible to use the batch facility for the Search API? – Ninja Sep 26 '13 at 22:57
0

The Topic API has you put the topic's id in the path and this limits it to one topic per call. Some of the language API's have you pass a list of id's but they'll only accept a list with one topic.

bwgz57
  • 51
  • 4