API Abstract

This page will describe the API Abstract class - the one which all the API classes extend to get some common functionality. Use this to build your own API class for custom APIs you defined in the Diffbot UI.

class Swader\Diffbot\Abstracts\Api

  • $url (string) – The URL of the page to process

InvalidArgumentException if the URL is invalid AND not the word “crawl”

This class takes a single argument during construction, the URL of the page to process. Alternatively, the argument can be “crawl”, if the API is to be used in conjunction with the Swader\Diffbot\Api\Crawl API.

Swader\Diffbot\Abstracts\Api::setTimeout($timeout = 30000)
  • $timeout (int) – Optional. The timeout, in milliseconds. Defaults to 30,000, a.k.a. 30 seconds



InvalidArgumentException if the timeout value is invalid (negative or not an integer)

Setting the timeout will define how long Diffbot will keep trying to fetch the API results. A timeout can happen for various reasons, from Diffbot’s failure, to the site being crawled being exceptionally slow, and more.



Returns:Swader\Diffbot\Entity\EntityIterator The return value will be an iterable collection of appropriate entities. Refer to each API’s documentation for details on entities returned from each API call.

When the API instance has been fully configured, this method executes the call.


$result = $api->call();
foreach ($result as $entity) { /* ... */ }


This method is called automatically when Swader\Diffbot\Abstracts\Api::call is called. It builds the URL which is to be called by the HTTPClient in Swader\Diffbot\Diffbot::setHttpClient, and returns it. This method can be used to get the URL for the purposes of testing in third party API clients like Postman.


$api-> // ... set up API
$myUrl = $api->buildUrl();