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

warpig's avatar
Level 12

Making 2 API GET requests

Hey guys how can I make 2 requests for 2 different end points on a URL that comes from an API?

    public $search;
    public $searchResults = [];
    
    public function updatedSearch($newValue)
    {
        if(strlen($this->search) < 3) {
            $this->searchResults = [];
            return;
        }

        $response = Http::get('http://thvid-api.herokuapp.com/videos/game/'.$this->search)->json();
        
        $this->searchResults = $response;
    }

This works fine but I wish to make another query in the same component but to another URL. Is that possible? Does a method exists for this? Thanks.

0 likes
5 replies
neilstee's avatar
neilstee
Best Answer
Level 34

@warpig it should be possible:

    public $search;
    public $searchResults = [];
    
    public function updatedSearch($newValue)
    {
        if(strlen($this->search) < 3) {
            $this->searchResults = [];
            return;
        }

        $response1 = Http::get('http://thvid-api.herokuapp.com/videos/game/'.$this->search)->json();
        $response2 = Http::get('http://site.com/'.$this->search)->json();
        
        $this->searchResults = array_merge($response1, $response2);
    }

For array_merge, you might need to json_decode the responses before array_merge then json_encodeagain.

warpig's avatar
Level 12

Apply json_decode to both responses?

neilstee's avatar

@warpig yes but you need to test it because you translated your responses to JSON using ->json().

warpig's avatar
Level 12

I see, it worked just fine with the json() thanks!

Please or to participate in this conversation.