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

CookieMonster's avatar

HTTP request for external API?

I tried to implement a payment API into my system but I have some doubts regarding the HTTP requests being called for the API and I wanted to clear the confusion.

As far as I know in general, GET request is used to retrieve data or information from a server while POST request is used to submit data to the server.

In my route calling the api, it will look something like:

Route::get('toyyibpay','ToyyibpayController@createBill')->name('toyyibpay-create');

Controller:

public function createBill(Request $request){
       
        $credit = ($request->amount)*100;
        $option = array(
            'userSecretKey'=>config('toyyibpay.key'),
            'categoryCode'=>config('toyyibpay.category'),
            'billName'=>'Fxxxx',
            'billDescription'=>'Top Up Credit',
            'billPriceSetting'=>1,
            'billPayorInfo'=>0,
            'billAmount'=>$credit,
            'billReturnUrl'=>route('toyyibpay-status'),
            'billCallbackUrl'=>route('toyyibpay-callback'),
            'billExternalReferenceNo' => '',
            'billTo'=>'',
            'billEmail'=>'',
            'billPhone'=>'',
            'billSplitPayment'=>0,
            'billSplitPaymentArgs'=>'',
            'billPaymentChannel'=>0,
            'billContentEmail'=>'Thank you for using our platform!',
            'billChargeToCustomer'=>2
          );  

    
          $url = 'https://dev.toyyibpay.com/index.php/api/createBill';
          
          $response = Http::asForm()->post($url,$option);
          
          $billCode = $response[0]['BillCode'];
          //dd($billCode);
         
         
          

          return redirect('https://dev.toyyibpay.com/'.$billCode);
    }

As shown in the method, I am passing data(parameters) to the server. As of now, everything works fine. My doubt is shouldn't a post request be used since this involves data submitting?

0 likes
2 replies
Tray2's avatar

I would do a post request here yes. Since you probably are submitting sensitive information,

CookieMonster's avatar

Though how come GET request still works?

So my understanding is correct?

Though GET request also allow to retrieve data.

Please or to participate in this conversation.