Laravel 5 REST CRUD Client

Is there a way in Laravel 5 to do CRUD with REST? I have a REST API already using CodeIgniter and I want my Laravel application to communicate with it.

So let's say I have this url to get the whole gender: http: //api.local/api/api_gender/gender

In my controller, it seems that I can do something like this:

$results = json_decode(file_get_contents('http://api.local/api/api_gender/gender/')); 

But I do not know whether to do it right.

Now, how can I do this if I want to add a new floor in Laravel? In CI, I could just use the library of Phil's remains and just use $this->rest->put('http://api.local/api/api_gender/gender/', $parameters)

+6
source share
1 answer

I would use Guzzle , a very popular, flexible HTTP client for PHP. As far as I know, this is one of the most popular packages for HTTP requests in PHP.

 $client = new GuzzleHttp\Client(); $client->put('http://api.local/api/api_gender/gender/', ['json' => ['foo' => 'bar']]); // or $client->put('http://api.local/api/api_gender/gender/', ['query' => ['foo' => 'bar']]); 
+9
source

Source: https://habr.com/ru/post/983179/


All Articles