requestView.php 747 B

123456789101112131415161718192021222324252627
  1. <?php
  2. function requestView($viewUrl, $key){
  3. //viewURL example: "auth/_design/chkauth/_view/authv1/"
  4. $key = json_encode($key);
  5. require_once('vendor/autoload.php');
  6. $url = "http://127.0.0.1:5984/"; // edit this line! Put your URL here
  7. try {
  8. $client = new \GuzzleHttp\Client(["base_uri" => $url]);
  9. $response = $client->request("GET",$viewUrl . "?key=" . $key);
  10. if($response->getStatusCode() == 200) {
  11. return(json_decode($response->getBody(),true));
  12. }
  13. } catch (\GuzzleHttp\ExceptionRequestException $e) {
  14. // couldn't connect
  15. return false;
  16. } catch (\GuzzleHttp\ExceptionClientException $e) {
  17. // 400-class error
  18. return false;
  19. } catch (\GuzzleHttp\ExceptionServerException $e) {
  20. // 500-class error
  21. return false;
  22. }
  23. }
  24. ?>