nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 299 forks source link

More convenient parseWith method. #163

Open zealotrunner opened 9 years ago

zealotrunner commented 9 years ago

I think it'll be easier to use parseWith() if the method support following 'features'.

  1. More 'straight-through' Now we have to

    $response = \Httpful\Request::get('http://www.example.com?p=1')
       ->parseWith(function($body) {
           // 
           return parsedMessage($body);
        })
        ->send();
    $message = $response->body;

    My Suggention

    $message = \Httpful\Request::get('http://www.example.com?p=1')
       ->xParseWith(function($body) {
           // 
           return parsedMessage($body);
        })
        ->send();
  2. Pass $url directly in Now we have to

    $url = 'http://www.example.com?p=1';
    $response = \Httpful\Request::get($url)
       ->parseWith(function($body) use($url) {
           // 
           return parsedMessage($body, $url);
        })
        ->send();

    My Suggention

    $response = \Httpful\Request::get('http://www.example.com?p=1')
       ->parseWith(function($body, $url) {
           // 
           return parsedMessage($body, $url);
        })
        ->send();
evangelion1204 commented 8 years ago

In general it would be helpful to know the headers too. In case you need to handle things like uncompression.