Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DDSameera's avatar

3rd Party API Service Class

I want to call 3rd party API service and do some activities. So i prepared this Service class

Actually I want to know where i m in Right Track. or Do i need to follow up any other way to accomplish my task . Please let me know your suggestion.

<?php


namespace App\Services;


use GuzzleHttp\Client;

class VideoAPI
{


    protected $token;
    protected $apiUrl;
    protected $headers;
    protected $query;


    public function __construct()
    {

        $token =  config('app.token');
        $apiUrl = config('app.apiUrl');


        $headers = [
            'Authorization' => 'Bearer ' . $token,
        ];

        $query = [
            'page' => 1,
            'size' => 100,
            'sort' => 'name:-1',

        ];

        $this->apiUrl = $apiUrl;
        $this->token = $token;
        $this->headers= $headers;
        $this->query = $query;



    }

    public function getProjects()
    {

        $client = new Client();

        $client = $client->request('GET', $this->apiUrl, [
            'headers' => $this->headers,
            'query' => $this->query
        ]);



        return $client->getBody()->getContents();
    }

}
0 likes
4 replies
DDSameera's avatar

@amirkamizi , Can we create ServiceProvider class for this ? what is the correct way to handle this kind of situation ?

Please or to participate in this conversation.