Tuesday, 9 February 2021

Guzzle Http Client Request

 composer require guzzlehttp/guzzle

GET REQUEST

public function getGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $request = $client->get('http://example.com');
    $response = $request->getBody();
   
    dd($response);
}


POST REQUEST

public function postGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://example.com/api/posts";
   
    $data['name'] = "codechief";
    $request = $client->post($url,  ['body'=>$data]);
    $response = $request->send();
 
    dd($response);
}


PUT REQUEST

public function putGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://example.com/api/posts/1";
    $data['name'] = "codechief";
    $request = $client->put($url,  ['body'=>$data]);
    $response = $request->send();
   
    dd($response);
}


DELETE REQUEST

public function deleteGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://example.com/api/posts/1";
    $request = $client->delete($url);
    $response = $request->send();
 
    dd($response);
}

3 comments:

  1. Thank you for sharing this informative post. Looking forward to reading more.
    Laravel Development Services

    ReplyDelete
  2. Thanks a lot for your interesting article. I have been searching for such message for a very long time. Not all your content is completely clear to me, even though it is definitely interesting and worth reading. Goviralhost Review

    ReplyDelete

Machine Learning - Potato Leaf Disease Prediction

Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...