Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

All wrappers is built around a request method. In version 6.0, each request method has its own method: doGet for GET-requests, doPost for POST-requests, doDelete for DELETE, and so on. In 6.1 we stay with the request method. NetWrapper and MODULE_CURL however supports the old do-methods, even if it is highly recommended to not use those methods. The difference between this module and the others is that NetWrapper finds a preferred driver where curl has priority. If curl is unavailable, NetWrapper will automatically try to run with internal streams by default.

I've created a method in netWrapperTest to demonstrate, that will be left over there for you to test with:

...

In this example, we want to get data from https://ipv4.netcurl.org which is a page that returns the content of your request as a json object. To get the json object correctly formatted so you don't have to parse it yourself we use getParsed()-method. Feel free to test here. If you explicitly need to test IPv6, you can use https://ipv6.netcurl.org for this.

Doing it on a simple row

A big difference between 6.0 and 6.1 is the chaining, which did not exist in the old versions as it supported PHP 5.3 in the "good old (horrible) times". Almost everything in netcurl 6.1 is chained, so the above method could be pushed into one simple row, like this:

Code Block
languagephp
themeEmacs
titleThe oneliner
 $parsed = (new NetWrapper())->request(sprintf('https://ipv4.netcurl.org/'))->getParsed();
static::assertNotEmpty(filter_var($parsed->ip, FILTER_VALIDATE_IP));