Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can we call url() with port number in Laravel controller. Node server is running on different port that 8001 and Laravel port is 8000?

My Laravel application is running on 127.0.0.1:8000 port but my node server is running on port 127.0.0.1:8001 which has a node script that scrapes data. how can I call the URL function to point out the 127.0.0.1:8001 port from a Laravel controller to run such a script?

for example, check the comment in the index() in DataScrapingController

class DataScrapingController extends Controller
{
    public function index()
    {   
        // Here is the below URL I want to call this URL when a user calls this index 
        //controller function 

        "http://127.0.0.1:8001/scrape"
        


        // After scraping the data when this **http://127.0.0.1:8001/scrape** URL call. which 
        // saves the data in the output.json file here I get the output.json file and return the 
        // data to the data-scraping blade file.

        $data = json_decode(file_get_contents('output.json'));
        return view('data-scraping', compact('data')); 
    }
}

Below image is the node hierarchy in the Laravel application

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

thanks in advance

>Solution :

Use the Laravel Http wrapper around guzzle

$response = Http::get("http://127.0.0.1:8001/scrape");

Please see https://laravel.com/docs/9.x/http-client#main-content

Make sure you are not running php artisan serve as this can only handle one connection at once.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading