Skip to content

Instantly share code, notes, and snippets.

@laser
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laser/a95e2d510cc0aefc7eee to your computer and use it in GitHub Desktop.
Save laser/a95e2d510cc0aefc7eee to your computer and use it in GitHub Desktop.
Batch Client - PHP
#!/usr/bin/env php
<?php
include_once("./lib/barrister.php");
$barrister = new Barrister();
$client = $barrister->httpClient("http://localhost:3000/v1/todos");
$batch = $client->startBatch();
$batchTodoManager = $batch->proxy("TodoManager");
$batchTodoManager->createTodo([ "title" => "Call Mom", "completed" => false ]);
$batchTodoManager->createTodo([ "title" => "Call Dad", "completed" => false ]);
$batchTodoManager->createTodo([ "title" => "Wash car", "completed" => false ]);
$batchTodoManager->createTodo([ "title" => "Eat Ham", "completed" => false ]);
$result = $batch->send();
foreach ($result as $i=>$res) {
if ($res->error) {
// $res->error is a BarristerRpcException, so you can raise if desired
echo "err.code=" . $res->error->code . "\n";
}
else {
// result from a successful call
var_dump($res->result);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment