Giter Site home page Giter Site logo

zttp's People

Contributors

adamwathan avatar alepeino avatar andreaselia avatar bastien-phi avatar dwightwatson avatar faustbrian avatar freekmurze avatar fyrts avatar jerguslejko avatar m1guelpf avatar metalcamp avatar ntzm avatar richardkeep avatar sebdesign avatar sixlive avatar sjmarve avatar taylorotwell avatar vmitchell85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zttp's Issues

Use shared Guzzle client instance to reuse cURL handle

Hi !

it looks like the feature developed in commit f49f921 has been reverted recently.
Modifying PendingZttpRequest::buildClient with

function buildClient()
{
    echo "building a client\n";
    return new \GuzzleHttp\Client(['handler' => $this->buildHandlerStack()]);
}

we expect to have a single building a client when calling

Zttp::get('http://some.url');
Zttp::get('http://some.url');

Actually, building a client is echoed twice.

Is there any breaking change that makes the reusability of the Guzzle client instance ?

How to post a JSON type parameter?

Sample:
$response = Zttp::asFormParams()->post($url, [
'foo' => 'bar',
'baz' => 'qux',
]);

'[ 'foo' => 'bar', 'baz' => 'qux',]' is a array? How to post '{ 'foo' : 'bar', 'baz' : 'qux'}'?

async method

Hey,I want to know how to request data asynchronously,like asyncPost, asyncGet....

Still maintained?

With several issues and pull-requests open for years, it looks like support for this packages is very lacking.
How can we help with maintenance and merging updates?
Is it possible to add more mainainers?

Query String Problem Parsing

Url looks like this https://api.test/starter/province?0%5Bid%5D=12
the code:

public function request(string $path, array $param = [], $type = 'GET')
{
        $response = Http::withHeaders(['key' => $this->apiKey])
            ->get($this->url($path), [
            $param
        ]);

        //return $response->body();
        return $response; //debug
}

public function getProvince($idProvince)
{
      return $this->request('province', ['id' => $idProvince]);
}

and consume the function

var_dump($test->getProvince(12));

output

 private $handlerStats =>
    array(31) {
      'url' =>
      string(56) "https://api.test/starter/province?0%5Bid%5D=12"
      'content_type' =>
      string(16) "application/json"
      'http_code' =>
      int(200)
      'header_size' =>
      int(126)
      'request_size' =>
      int(164)
      ...
    }

so how can i send URL like this https://api.test/starter/province?id=12

Thanks

Guzzle v7 Support

I'm not sure how much effort it would actually take, but are there plans to support Guzzle v7 in the near future?

Send form-data

Hi guys,
I need to post a form data values as these (generated with postman):

$request->setBody('
Content-Disposition: form-data; name="PARAMS"

{
	"richiesta": "insertAnagrafiche",
	"payload": {
		"societa": "LAZ-RM99999",
		"anagrafiche": [{
			"COGNOME": "Arena",
			"NOME": "Angflgca",
			"SESSO": "2",
			"CF": "ZZZZZZZZZZZ",
			"TELEFONO": "",
			"EMAIL": "",
			"COD_COMUNE_NASCITA": "H501",
			"CAP_NASCITA": "00100",
			"DATA_NASCITA": "1900-01-01",
			"INDIRIZZO": "",
			"COD_COMUNE_RESIDENZA": "H501",
			"CAP_RESIDENZA": "00100"
		}]
	}
}');

How can I do this with zttp?

Doesn't work with older versions of Laravel due to Collection namespace collision

This may be entirely to do with some oddity of the project where I'm trying to switch to Zttp (Lumen v5.1.7, due to requirements back when it was built and lack of time/resources to rework it in 5.5 or full Laravel), but the changes in runBeforeSendingCallbacks in commit 7b6dddc throw an error for me on any request, including a simple get with no parameters:

$response = Zttp::get('https://github.com');

PHP error: Undefined property: Illuminate\Support\Collection::$each in [...]/vendor/kitetail/zttp/src/Zttp.php on line 178

Using kitetail/zttp v0.3.0 and illuminate/support v5.1.41.
Illuminate\Support\Collection definitely has the each function, but I'm probably in over my head as to what I'm doing wrong. If I switch back to array_reduce and [] instead of collect(), there are no errors and the call behaves as expected. Any idea what I'm running up against? Again, fully expecting it to be something on my end (and I'm not expecting help with that) with the older Lumen/Illuminate versions in play rather than a Zttp issue, but I figured I could check.

URL Query variable does not work with .

I'm trying to do a GET with a query variable being:

?api.version=1

Because of parse_str called in parseQueryParams method, it converts that variable to:

?api_version=1

I'm sure you had a reason for parse_str, so zttp might just not work for me, but thought I'd report it in case that was an unintended problem. Thanks.

Tests not working

Hey,
i most likely missed something obvious here, but when i clone the repo, run composer install and composer test phpunit gets stuck.

Logs:

[2017-10-03 16:09:01] lumen.ERROR: Illuminate\Container\EntryNotFoundException in /Users/ronhansen/code/SideProjects/zttp/vendor/illuminate/container/Container.php:598
Stack trace:
#0 /Users/ronhansen/code/SideProjects/zttp/tests/server/public/index.php(21): Illuminate\Container\Container->get('/get', Object(Closure))
#1 {main}

Thank you for any help

HEAD requests?

Am I going crazy or does this package not do head requests?

if so can this be implemented? its kinda fundamental for a requests package.

Keep tagging and pushing new versions

This library is still very much in dev phase, however for testing purposes I'd like more in-between versions to be tagged (and pushed to packagist).
This helps us to keep playing with newer versions without using master directly.

Url query variable in post request doesn't work

Im using a web api that need a post request to an url with one query parameter:

https://inbox.centiacrm.com/?/Ajax/

When i send the request it doesn't work (im sure the api works, i made the request with postman and guzzle and works fine)

I have two theories, doesn't accepts slash as query params or maybe the reason is that the params doesnt have value (?/Ajax/=value)

Example with Zttp (should return a json response (doesn't work returns html)

(string) \Zttp\Zttp::asFormParams()->post('http://inbox.centiacrm.com?/Ajax/', [
            'Action' => 'SystemGetAppData',
            'AccountID' => '263'
        ])->getBody()

Example with Guzzle (it works)

(string) (new \GuzzleHttp\Client())->post('http://inbox.centiacrm.com?/Ajax/', [
            'form_params' => [
                'Action' => 'SystemGetAppData',
                'AccountID' => '263'
            ]
        ])->getBody()

This is the webapi
(https://afterlogic.com/docs/webmail-pro/integration-and-development/web-api)

kitetail/zttp not working for latest version of laravel

I got the error below while trying to install zttp for laravel version 7.20

Console error

Using version ^0.6.0 for kitetail/zttp
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for kitetail/zttp ^0.6.0 -> satisfiable by kitetail/zttp[v0.6.0].
- Conclusion: remove laravel/framework v7.20.0
- Conclusion: don't install laravel/framework v7.20.0
- kitetail/zttp v0.6.0 requires tightenco/collect ^5.4 -> satisfiable by illuminate/support[5.4.x-dev, 5.5.x-dev].
- don't install illuminate/support 5.4.x-dev|don't install laravel/framework v7.20.0
- don't install illuminate/support 5.5.x-dev|don't install laravel/framework v7.20.0
- Installation request for laravel/framework (locked at v7.20.0, required as ^7.0) -> satisfiable by laravel/framework[v7.20.0].

Laravel version

Laravel Framework 7.20.0

Sending [] in URL Query Params get encoded

I'm trying to use this library to interact with the Zendesk API. Using the following code, I'm requesting the Users endpoint with some query params in the URL ?role[]=agent&role[]=admin

However, when I have this code I get an error response back from Zendesk saying the params aren't correct.

Request to API

$req = Zttp::withHeaders([
    'Authorization' => 'Bearer MYTOKEN',
])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json?role[]=agent&role[]=admin');

dd($req->json());

Error from API

^ array:1 [▼
  "error" => array:2 [▼
    "title" => "Invalid attribute"
    "message" => "You passed an invalid value for the role attribute. Invalid parameter: role must be a string from api/v2/users/index"
  ]
]

If I look at the URL which Zttp actually sends it appears as:
https://MYSUBDOMAIN.zendesk.com/api/v2/users.json?role%5B0%5D=admin&role%5B1%5D=agent

I have also tried using:

    $req = Zttp::withHeaders([
        'Authorization' => 'Bearer MYTOKEN',
    ])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json', [
        'role' => 'admin',
        'role' => 'agent',
    ]);

and

    $req = Zttp::withHeaders([
        'Authorization' => 'Bearer MYTOKEN',
    ])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json', [
        'role[]' => 'admin',
        'role[]' => 'agent',
    ]);

Using this approach, Zendesk get's only one of the parameters.
Does anyone have any suggestions how I can get this working? Via the query params is the only way Zendesk will accept.

preventing encoding of a query

using Guzzle works like so
$response = $client->get('http://localhost:8002/monitoring/stats?mount=/test.mp3', [ 'auth' => ['blah', $this->pass], ]);

using Zttp fails with "The specified mount is invalid"
and the url looks like this http://localhost:8002/monitoring/stats?mount=%2Ftest.mp3
with the code:

$response = Zttp::timeout(2)->withBasicAuth("blah", $this->pass)->get("http://localhost:8002/monitoring/stats?mount=/test.mp3");

so how can i send the mount as /test.mp3 not %2Ftest.mp3

Multicurl support?

Hey there i know guzzle supports multi-curl so that all the responses are sent simultaneously, does this?

awesome package by the way, i love how clean my code gets with this.

Reuse Guzzle Client

Instead of creating a new instance of a Guzzle client for each request, you should have a shared/singleton instance that you reuse. This would reuse the underlying cURL handle as well, which is an optimization if you end up doing more than one request to the same host.

Suggestion: add a small testserver

The idea of using a real server to run the tests against is great. But as it stands now there's a big downside: unless you share your value of TEST_SERVER_URL contributors must built up their own testserver with the expected endpoints and responses to test the package locally.

My suggestion is that you include a small node base server to the tests.

An example of such as server can be found in the tests of spatie/laravel-uptime-monitor. In those tests we added some methods to let our server respond what we want. To test zttp the test server would only contain some hard coded endpoints.

Downsides:

  • you have to start up that node server before running the tests

Upsides:

  • no real world testserver needed
  • it's still an end to end test, incompatible changes in Guzzle will be catched
  • contributors can run tests locally
  • tests can be run even when not connected to the internet

In case you were wondering Travis can also use that node server.

If you're open for this I can whip up a PR that adds a testserver to the package.

Multiple headers with the same name

I am trying to connect to a server that returns three headers with the same name: Set-Cookie. When I do a simple

dd(Zttp::asFormParams()->post($url, [
    // some data
])->headers()->toArray());

it returns an array of headers, but Set-Cookie is only one there.

Expected: There should be an array of cookies returned:

[
    'Set-Cookie' => [
        'cookie-1',
        'cookie-2'
    ],
    // some other data
]

Actual: Only first cookie is returned

[
    'Set-Cookie' => 'cookie-1',
    // some other data
]

Trying to understand the tap function

Hey there. I hope you'll excuse me for this non-issue but I was going thru the code after hearing you talk about it on the Full stack podcast and I can't quite understand what the tap function is supposed to do. Would you mind sparing a second to explain it?

Thanks! :D

Cannot use custom handler / Mock

In unit tests I would like to mock guzzle handler stack. (see here)

$mock = new MockHandler([
    new Response(202, ['Content-Length' => 0]),
]);

$handlerStack = HandlerStack::create($mock);

PendingZttpRequest::new()->withOptions(['handler' => $handlerStack])->post('/url');

it returns error:

Undefined property: Zttp\PendingZttpRequest::$cookies
/vendor/kitetail/zttp/src/Zttp.php:182
/vendor/kitetail/zttp/src/Zttp.php:355
/vendor/kitetail/zttp/src/Zttp.php:184
/vendor/kitetail/zttp/src/Zttp.php:148

Update:

To hack this just create wrapper around Zttp and override buildHandlerStack method to either take handler from options or create handler using HandlerStack::create() as before.

Spacing within tap() for readibility

The one thing that has kept me from using tap() in a lot of situations is the sheer verbosity of callback definition, and the lack of spacing directly after it.

Consider the following, where the logic $this->bodyFormat = $format; is lost within the tap function:

function bodyFormat($format)
{
    return tap($this, function ($request) use ($format) {
        $this->bodyFormat = $format;
    });
}

I wonder if this style would be nicer for tapped functions:

function bodyFormat($format) {
    return tap($this, function ($request) use ($format) 
    {
        $this->bodyFormat = $format;
    });
}

It's the same number of lines, but keeps the logic as the focus, and shifts the tap() to part of the function scaffolding.

delete http method will attach an empty object in http body

Hi!
When I use delete method, the http body will attach an empty object. It is not the same as GuzzleHttp.

    function delete($url, $params = [])
    {
        return $this->send('DELETE', $url, [
            $this->bodyFormat => $params,
        ]);
    }

Maybe takeaway $this->bodyFormat => $params, when the $params is an empty array can fix this problem.

Any chance of a new release for withOptions()?

I updated the Zttp package with composer and noticed the withOptions() function wasn't available. It's a pretty handy function, you should release it for the people.

Thanks guys 👋

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.