Skip to content
InfinityKnow

InfinityKnow

Infinity Knowledge (IK) : Technology, Articles, Topics, Facts or many More.

  • Home
  • Education
    • yttags
    • Make Money
    • Jobs
    • Programming
      • Technology
      • Web Design
      • WEB HOSTING
      • Interview
  • Entertainment
    • pakainfo
    • Sports
    • Tips and Tricks
      • Law
      • Photography
      • Travel
  • Health
    • Insurance
    • Lifestyle
      • Clothing
      • Fashion
      • Food
  • News
    • Insurance
      • Auto Car Insurance
      • Business Insurance
    • Donate
    • California
  • News
    • Political
  • Home Improvement
  • Trading
    • Marketing
    • Top Tranding
    • Business
    • Real Estate
  • Full Form
  • Contact Us
  • Laravel Pass Data To All Views Example Technology
  • Ghalib shayari
    Ghalib shayari Shayari
  • C# Sorted Dictionary Tutorial with Examples Technology
  • facts of life Facts
  • How can we clean the wooden doors of kitchen cabinets ? Business
  • Angular Top 10 Interview Questions Technology
  • Simple Pagination With AngularJS and JSON using PHP
    Simple Pagination With AngularJS and JSON using PHP Technology
  • AngularJS Custom Service Factory with Example
    AngularJS Custom Service Factory with Example Technology

PHP cURL API calls POST GET PUT DELETE RESTful CRUD

Posted on February 18, 2019 By admin No Comments on PHP cURL API calls POST GET PUT DELETE RESTful CRUD

PHP cURL API calls POST GET PUT DELETE RESTful CRUD</h2

Today, We want to share with you PHP cURL API calls POST GET PUT DELETE RESTful CRUD.
In this post we will show you cURL API calls with PHP and json data (GET – POST – PUT – DELETE), hear for RESTful CRUD using GET, POST, PUT and DELETE we will give you demo and example for implement.
In this post, we will learn about Rest API And HTTP Methods (GET, POST, PUT, DELETE) with an example.

Good And Easy my first release of Configuring CORS for the REST API PhpRestful API Doc I had to Source code develop a Enabling Cross Origin Requests for a RESTful Web Service cross-method solution to allow users Access-Control-Allow-Origin – HTTP to test REST cURL API calls with PHP and json data requesting directly from the documentation and Fetch Main 3 parts of the API response :

Syntax : Access-Control-Allow-Origin
[php]
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin:
[/php]

Handling CORS on the server CORS and caching

  • Header
  • Body
  • HTTP Status Code
  • How to use PHP 4 different methods :

    • DELETE,
    • GET,
    • POST,
    • PUT.

    Also I needed to be able to customize CURL API CALLS WITH PHP MySQLi AND JSON DATA (GET POST PUT DELETE) the desired Data content type to Retrive response (JSON, CSV, XML, etc).

    [php]
    $get_data = callAPI(‘GET’, ‘https://api.infinityknow.com/get_url/’.$user[‘User’][‘user_id’], false);
    $dataresults = json_decode($get_data, true);
    $errors = $dataresults[‘dataresults’][‘errors’];
    $data = $dataresults[‘dataresults’][‘data’][0];
    [/php]

    Here is the commented source code that I wrote to achieve that :

    PHP API Request Url

    Set the call data Request Url (without any Parameters) set here

    [php]
    $web_services_req_url = ‘http://api.infinityknow.com/user/info/’;
    [/php]

    PHP cURL DELETE, GET, POST or PUT request and response Example

    Which API Request Method do I want to use ? Like as a ( DELETE, GET, POST or PUT )

    config.php

    Let’s first of all set all Request Like as a config.php Parameters (api_key, token, user_id, etc)

    [php]
    $web_services_name = ‘GET’;

    $web_services_param = array(
    ‘api_key’ => ‘gF7mcpakaInfodotcom726sL’,
    ‘token’ => ‘hnFGkrupalift8GE8AVTjaydeeporgthinfiNityKnowt’,
    ‘user_id’ => 9898
    );
    [/php]

    PHP Method DELETE, GET, POST or PUT Example

    DELETE, GET, POST or PUT Method PHP API

    [php]
    $liveCurl = curl_init();
    curl_setopt($liveCurl, CURLOPT_RETURNTRANSFER, TRUE);

    if ($web_services_name == ‘DELETE’)
    {
    curl_setopt($liveCurl, CURLOPT_CUSTOMREQUEST, ‘DELETE’);
    curl_setopt($liveCurl, CURLOPT_POSTFIELDS, http_build_query($web_services_param));
    }

    if ($web_services_name == ‘GET’)
    {
    $web_services_req_url .= ‘?’ . http_build_query($web_services_param);
    }

    if ($web_services_name == ‘POST’)
    {
    curl_setopt($liveCurl, CURLOPT_POST, TRUE);
    curl_setopt($liveCurl, CURLOPT_POSTFIELDS, http_build_query($web_services_param));
    }

    if ($web_services_name == ‘PUT’)
    {
    curl_setopt($liveCurl, CURLOPT_CUSTOMREQUEST, ‘PUT’);
    curl_setopt($liveCurl, CURLOPT_POSTFIELDS, http_build_query($web_services_param));
    }
    curl_setopt($liveCurl, CURLOPT_HTTPHEADER, array(‘Accept: application/json’));

    curl_setopt($liveCurl, CURLOPT_URL, $web_services_req_url);

    curl_setopt($liveCurl, CURLOPT_HEADER, TRUE);

    curl_setopt($liveCurl, CURLOPT_SSL_VERIFYPEER, false);

    $api_response = curl_exec($liveCurl);
    $web_services_response = curl_getinfo($liveCurl);
    curl_close($liveCurl);

    $api_response_header = trim(substr($api_response, 0, $web_services_response[‘header_size’]));
    $api_response_body = substr($api_response, $web_services_response[‘header_size’]);

    echo $web_services_response[‘http_code’];

    echo $api_response_header;

    echo $api_response_body;
    [/php]

    We hope you get an idea about PHP HTTP Methods RESTful API Structure
    We would like to have feedback on my Information blog .
    Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
    If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

    We hope This Post can help you…….Good Luck!.

    Related posts:

    1. PHP curl POST Sending JSON Data
    2. PHP Simple cURL API call using POST
    3. Angular 6 Restful Http Post and Get Web Api Calls
    4. AngularJS RESTful Web Service GET and POST API
    READ :  AngularJS Image Slider - AngularJS Image Carousel Slider
    Technology, Laravel, MySQL, PHP Tags:curl delete request with data php, how to get data from api in php, how to get response from api in php, php api call json, php curl get, php curl post, php curl post json, php curl rest api exampl

    Post navigation

    Previous Post: C# Boxing & Unboxing Tutorial with Examples
    Next Post: Angularjs Custom Animation nganimate Examples

    Related Posts

    • Vue Restful API and axios API Example – Vue js rest api authentication
      Vue Restful API and axios API Example – Vue js rest api authentication Technology
    • Laravel 6 FirstorCreate Increment and update column using Eloquent Technology
    • Comprehensive Guide
      A Comprehensive Guide to Choose the Vetiver Fragrances Articles
    • Vuejs Facebook Login using PHP - vue facebook-login
      Vuejs Facebook Login using PHP – vue facebook-login Technology
    • Vuejs Computed properties – vue watch computed property Examples
      Vuejs Computed properties – vue watch computed property Examples Technology
    • C# SortedList Tutorial with Examples Technology

    Leave a Reply Cancel reply

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

    Categories

    • Account web hosting (1)
    • AngularJs (277)
    • Articles (143)
    • Asp.Net (49)
    • Astrology (2)
    • Attorney (7)
    • Auto Car Insurance (4)
    • Biography (2)
    • Business (9)
    • Business Insurance (3)
    • California (4)
    • Choose the web hosting (1)
    • Clothing (6)
    • cloud (8)
    • Cloud data storage (2)
    • Credit (1)
    • Dedicated hosting server web (1)
    • Dedicated server web hosting (1)
    • Dedicated web hosting (1)
    • Degree (11)
    • Design (9)
    • Differences shared hosting (1)
    • Donate (2)
    • Education (37)
    • Energy web hosting (1)
    • Entertainment (6)
    • Facts (12)
    • Fashion (3)
    • Finance (3)
    • Food (5)
    • full form (90)
    • Google Adsense (22)
    • Health (20)
    • Home Improvement (5)
    • Insurance (6)
    • Interview (2)
    • Jobs (6)
    • jquery (2)
    • jQuery (2)
    • Laravel (164)
    • Lawyer (4)
    • Lifestyle (6)
    • Loans (6)
    • Make Money (31)
    • Managed dedicated server (1)
    • Managed hosting solution (1)
    • Managed servers (1)
    • Marketing (8)
    • Mortgage (2)
    • Movies (21)
    • MySQL (180)
    • News (5)
    • Photography (1)
    • PHP (250)
    • Programming (18)
    • Quotes (75)
    • Real Estate (2)
    • SEO (9)
    • Shared web hosting (1)
    • Shayari (67)
    • Sports (5)
    • Status (34)
    • Stories (45)
    • suvichar (8)
    • Tech (3)
    • Technology (675)
    • Tips and Tricks (42)
    • Top Tranding (35)
    • Trading (28)
    • Travel (12)
    • Uncategorized (8)
    • VueJs (179)
    • Web Design (2)
    • WEB HOSTING (1)
    • Web hosting company (1)
    • Web hosting really (1)
    • Web hosting windows (1)
    • Which website hosting (1)
    • Wishes (13)
    • wordpress (15)

    Categories

    AngularJs (277) Articles (143) Asp.Net (49) Attorney (7) Business (9) Clothing (6) cloud (8) Degree (11) Design (9) Education (37) Entertainment (6) Facts (12) Food (5) full form (90) Google Adsense (22) Health (20) Home Improvement (5) Insurance (6) Jobs (6) Laravel (164) Lifestyle (6) Loans (6) Make Money (31) Marketing (8) Movies (21) MySQL (180) News (5) PHP (250) Programming (18) Quotes (75) SEO (9) Shayari (67) Sports (5) Status (34) Stories (45) suvichar (8) Technology (675) Tips and Tricks (42) Top Tranding (35) Trading (28) Travel (12) Uncategorized (8) VueJs (179) Wishes (13) wordpress (15)
    • Angular Live Autosuggest Autocomplete textbox Technology
    • sez full form – sez Kya Hai, Meaning and Abbreviation – What is the full form of sez? full form
    • Top 10 C# FEATURES And BENEFITS for Beginners Technology
    • Alcohol and Blood Pressure
      Know About Alcohol and Blood Pressure Articles
    • Top 10 ways to Increase Google AdSense Earnings CPC And CTR
      Top 10 ways to Increase Google AdSense Earnings CPC And CTR Google Adsense
    • AngularJS Introduction Tutorial Technology
    • Top Angular2 Interview Questions and answers
      Top Angular2 Interview Questions and answers Technology
    • Laravel Create REST API Step By Step with Authentication
      Laravel Create REST API Step By Step with Authentication Technology

    Copyright © 2022 InfinityKnow.

    Powered by PressBook News WordPress theme