zoukankan      html  css  js  c++  java
  • HelpersSimpleCurl

    HelpersSimpleCurl

    The SimpleCurl class is there to curl data from RESTful services. A lot of companies use it nowadays for example twitter, google and facebook.

    There are four methods available these are get, post and put.

    You will need to declare the SimpleCurl helper first to use these examples below. You can do it by adding a use statement at the top of the controller.

    use HelpersSimpleCurl as Curl

    How to do a get request

    This example will show you how to a get request to get the current bitcoin prices from coinbase

    // Get the spot price of a bitcoin it returns a json object.
    $spotrate = Curl::get('https://coinbase.com/api/v1/prices/spot_rate');
    $data['spotrate'] = json_decode($spotrate);

    The get request returned the data as json data we encoded it and passed it to our view.

    Inside your view you could simply do

    echo $data['spotrate']->amount;
    echo $data['spotrate']->currency;

    This should print out the currency and rate.

    How to do a post request

    This example will show you how to post a gist to github gists.

    // Post a gist to github
    $content = "Hello World!";
    $response = Curl::post('https://api.github.com/gists', json_encode(array(
      'description' => 'PHP cURL Post Test',
      'public' => 'true',
      'files' => array(
        'Test.php' => array(
          'content' => $content,
        ),
      ),
    )));    

    The response will be details of the file and the url where it's located.

    How to do a put request

    This example will show you how to do a put request to httpbin a test service for curl.

    $response = Curl::put('http://httpbin.org/put', array(
      'id' => 1,
      'first_name' => 'Nova',
      'last_name' => 'Framework'
    )); 
  • 相关阅读:
    KISSY 1.3.0 发布,淘宝 Web UI 库
    mongodb的监控与性能优化
    Aspose.Tasks 4.9.0 发布,Project 文件读写
    Fix8 0.6.6 发布,C++ 实现的 FIX 框架
    VIM Pal 1.1.0 发布,VIM 文件树列表
    QT 5.0 正式版发布,支持 C++11
    TWiki 5.1.3 发布,企业 Wiki 系统
    Apache Lucene 3.6.2 发布
    Apache Sqoop 1.99.1 发布
    JAXX 2.5.9 发布,XML用户界面框架
  • 原文地址:https://www.cnblogs.com/chunguang/p/5643199.html
Copyright © 2011-2022 走看看