Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Welcome to the MODULE_CURL replacement. Yes, this is the generic module that replaces MODULE_CURL which will become very clear if you take a look at the backwards compatible class MODULE_CURL directly in the codebase. It is recommended that you drop the use of MODULE_CURL as soon as possible as it is just there to help 6.0-users to stay alive. The backward compatibility is not entirely safe either, but if you prefer to stay with an autoselected wrapper for communication, this is the way. Autotests are documented in several places - here or here but if you're more comfortable with written examples here, you can stay.

Most of the wrappers are built the same way with a wrapper interface. This also makes it possible to build your own drivers. The NetWrapper is where you should start build your own drivers if you want to go that way. The wrappers included in the core set may be enough to get started for real, but if you want to do it a harder way, you can for example build a driver that runs through NetWrapper - but with support for Guzzle or Zend. This document does not yet cover those parts.

Getting started

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.

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

Simple GET Request
$wrapper = new NetWrapper();
$parsed = $wrapper->getParsed();
static::assertNotEmpty(filter_var($parsed->ip, FILTER_VALIDATE_IP));

In this example, we want to get data from 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 for this.

  • No labels