You should create your own client which follows the \Magento\Framework\HTTP\ClientInterface
. Easiest way to do this is by extending the class \Magento\Framework\HTTP\Client\Curl
. In your case this could look like following:
<?php
namespace Your\ModuleName\Model;
use \Magento\Framework\HTTP\Client\Curl
class Client extends Curl
{
/**
* Hostname
* @var string
*/
protected $_host = 'something.net';
/**
* @param string $ip
* @return string
*/
public function getJsonByIp($ip)
{
$this->get('/json/' . $ip);
return $this->getBody();
}
}
The usage
<?php
namespace Your\ModuleName\Model;
class MyModel
{
/**
* @var Client
*/
private $client;
/**
* MyModel constructor.
* @param Client $client
*/
public function __construct(
Client $client
) {
$this->client = $client;
}
/**
* @param string $ipAdd
* @return string
*/
public function getInfo($ipAdd)
{
return $this->client->getJsonByIp($ipAdd);
}
}
Of course you should define an own interface for your client and use DI.