kitetail / zttp Goto Github PK
View Code? Open in Web Editor NEWA developer-experience focused HTTP client, optimized for most common use cases.
License: MIT License
A developer-experience focused HTTP client, optimized for most common use cases.
License: MIT License
how to install it on laravel framework?
Hey,I want to know how to request data asynchronously,like asyncPost, asyncGet....
Any idea?
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.
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 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
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?
I'm not sure how much effort it would actually take, but are there plans to support Guzzle v7 in the near future?
I will set logger for zttp
please , teach me to use it
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:
Upsides:
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.
PHP Parse error: syntax error, unexpected 'new' (T_NEW) in
vendor/kitetail/zttp/src/Zttp.php on line 9
Use PHP7.1
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)
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.
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
Please tag a release version as asMultipart
method is not there in v0.2.0
but it is there in the tests and mentioned in the https://laravel-news.com/zttp-guzzle-wrapper
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?
Sample:
$response = Zttp::asFormParams()->post($url, [
'foo' => 'bar',
'baz' => 'qux',
]);
'[ 'foo' => 'bar', 'baz' => 'qux',]' is a array? How to post '{ 'foo' : 'bar', 'baz' : 'qux'}'?
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.
Cannot install the package as it does not work with Guzzle v7, are there any plans to add support for this?
EDIT: Closed as there is already a duplicate issue here #90
Hello, Adam. If you are busy on tailwind, please, let users of this package know :)
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 ?
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.
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.
I tried to use Zttp to write a crawler. I found that using two different ways to initiate a POST request would have different results.
Zttp::asFormParams()->post('http://example.com', [
'foo' => 'bar'
];
Zttp::post('http://example.com?foo=boo');
What is the difference between these two ways?
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
As title, I think it should add the visible keywords for all methods.
Such as public
and private
.
It can help use to know methods easily.
The ZttpRequest has more than one expression and thus violates the code style of this project.
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.
See topic. This needs fixing if you want anyone to use this.
The tap()
function does not return immediately and thus violates the code style:
Lines 203 to 206 in 1f61141
Hi, The Zttp::timeout() not work for 0.3.0, Can you release a new version?
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
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
]
example : Zttp::get('http://demo.com/sms?user=user&password=@123456');
the web server get full url is 'http://demo.com/sms?user=user&password=%40123456',
SMS server is a third-party server, so I can‘t use urldecode to modify parameters, how do I use Zttp to achieve the purpose
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.
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
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.
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 👋
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.