This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Curl get and post api in php


Trendy web sites is utilizing APIs for a lot of functions. Like for sending SMS, for sending EMAILs, for cloud storage, for cell app APIs, for cost gateways. And in addition for integrating some native options of cell apps or web sites.

You possibly can run simply your API utilizing php module CURL. And it’s virtually obtainable for all servers localhost or world servers.

There are two sorts of principally used API strategies GET and POST. Some others are PUT, PATCH, UPDATE, DELETE. However you possibly can run your utility by utilizing these two GET or POST strategies.



If you wish to run GET Technique API then you should use the code given beneath.

$url = 'https://apiprovider.com';

$headers =array();

$headers[] = 'X-Authorization-Token:fgfdg4545hKUertefgdds';

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$outcomes=curl_exec($ch);

curl_close($ch);
Enter fullscreen mode

Exit fullscreen mode



If you wish to run POST Technique API then you should use the code given beneath.

$headers =array(); 

$headers[] = 'X-Authorization-Token:fghjfj4erJGFDgwrhgfhgfh';

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $information);

$search_results=curl_exec($ch);

curl_close($ch);

return $search_results;
Enter fullscreen mode

Exit fullscreen mode

Within the each code above $url is your API Url, $headers is your API headers, $information is your array put up information passing to API and $outcomes is your API outcomes or output. So, simply use this code and comply with your API supplier’s documentation.

Now utilizing these codes, you possibly can run CURL in php, run SMS API in php, run E-mail API in php, run Fee Gateway API in php, run Google API in php, run Cloud API in php, run AWS API in php, run WordPress API in php and in addition Picture Manipulation API in php.

And in addition you should use this code for any PHP framework like Laravel, Cakephp, Codeigniter or php primarily based CMS like WordPress, Magento, Joomla and so forth.

This methodology can be useful to run REST API in php, XML API in php or JSON API in php.


Please like share subscribe and provides constructive suggestions to inspire me to jot down extra for you.

For extra tutorials please visit my website.

Thanks:)
Glad Coding:)

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?