1[[endpoint-closure]] 2=== Set the Endpoint closure 3 4The client uses an Endpoint closure to dispatch API requests to the correct 5Endpoint object. A namespace object will construct a new Endpoint via this 6closure, which means this is a handy location if you wish to extend the 7available set of API endpoints available. 8 9For example, we could add a new endpoint like so: 10 11[source,php] 12---- 13 14$transport = $this->transport; 15$serializer = $this->serializer; 16 17$newEndpoint = function ($class) use ($transport, $serializer) { 18 if ($class == 'SuperSearch') { 19 return new MyProject\SuperSearch($transport); 20 } else { 21 // Default handler 22 $fullPath = '\\Elasticsearch\\Endpoints\\' . $class; 23 if ($class === 'Bulk' || $class === 'Msearch' || $class === 'MPercolate') { 24 return new $fullPath($transport, $serializer); 25 } else { 26 return new $fullPath($transport); 27 } 28 } 29}; 30 31$client = ClientBuilder::create() 32 ->setEndpoint($newEndpoint) 33 ->build(); 34---- 35 36Obviously, by doing this you take responsibility that all existing endpoints 37still function correctly. And you also assume the responsibility of correctly 38wiring the Transport and Serializer into each endpoint.