Helpers\SimpleCurl

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 Helpers\SimpleCurl 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'
));

Helpers\SimpleCurl的更多相关文章

  1. Config

    Config Config App Auth Cache Database Languages Mail Modules Routing Session Config Settings for the ...

  2. ASP.NET Core 中文文档 第四章 MVC(3.6.1 )Tag Helpers 介绍

    原文:Introduction to Tag Helpers 作者:Rick Anderson 翻译:刘浩杨 校对:高嵩(Jack) 什么是 Tag Helpers? Tag Helpers 提供了什 ...

  3. ASP.NET Core 中文文档 第四章 MVC(3.6.2 )自定义标签辅助类(Tag Helpers)

    原文:Authoring Tag Helpers 作者:Rick Anderson 翻译:张海龙(jiechen) 校对:许登洋(Seay) 示例代码查看与下载 从 Tag Helper 讲起 本篇教 ...

  4. [asp.net core]定义Tag Helpers

    原文地址 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/authoring Getting started wi ...

  5. [asp.net core] Tag Helpers 简介(转)

    原文地址 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro What are Tag Helpers? ...

  6. Handlebars块级Helpers

    1.Handlebars简单介绍: Handlebars是JavaScript一个语义模板库,通过对view和data的分离来快速构建Web模板.它采用"Logic-less templat ...

  7. 在 ASP.NET MVC 中使用 HTML Helpers 的那些事

    在 ASP.NET MVC 中使用 HTML Helpers 方法,可以返回得到标准的 HTML 标签,就像 <input>.<button> 或者 <img> 等 ...

  8. 理解ASP.NET MVC中的HTML Helpers

    01 内联Html Helpers @helper listItems(string[] items) { <ol> @foreach (var item in items) { < ...

  9. CKEditor Html Helpers for ASP.NET MVC3 Razor/WebForms Views

    一.原生方法: 在 razor 中 使用Fckeditor 编辑内容,需要引入js <script src="@Url.Content("~/fckeditor/fckedi ...

随机推荐

  1. 开通GitHub以及使用笔记

    把小游戏的代码和博客迁移到GitHub上,路径是:https://github.com/GAMTEQ,欢迎访问 以下是使用GITHUB的一些命令 504  cd code 506  mkdir Fai ...

  2. c#调用c++ dll的几种类型(转)

    http://www.sosuo8.com/article-2012/dllleixingzhuanhuan.htm   在合作开发时,C#时常需要调用C++DLL,当传递参数时时常遇到问题,尤其是传 ...

  3. Tomcat 下配置OpenLayers proxy.cgi代理

    摘要:在OpenLayers访问WFS服务时,会遇到跨域的问题而导致服务无法访问.此时,需要在应用程序中设置代理,通过代理进行访问.本文介绍在tomcat进行proxy.cgi文件配置,以及在调用代理 ...

  4. Codevs No.1281 Xn数列

    2016-06-01 16:28:25 题目链接: Xn数列 (Codevs No.1281) 题目大意: 给定一种递推式为 Xn=(A*Xn-1+C)%M 的数列,求特定的某一项%G 解法: 矩阵乘 ...

  5. vim 操作

    vim -b test.bin vim 的 -b 选项是告诉 vim 打开的是一个二进制文件,不指定的话,会在后面加上 0x0a ,即一个换行符,这样若是二进制文件,则文件被改变了,后面多了一个0x0 ...

  6. 第二百六十四天 how can I 坚持

    现在上班闲的有点蛋疼,感觉没什么事,学不到什么东西. 到底要不要买房啊.也想买啊.愁人. 这辈子绝不会就这样. 睡觉.

  7. 用一个例子学习CSS的伪类元素

    CSS伪类元素是一个非常酷的东西!首先我们理解一下它,:before :after 伪类元素,也就是虚假的元素.它可以插入在元素的前面或者后面,而在HTML文档结构中,它却是不存在的,因为Js是无法通 ...

  8. jquery easyui将form表单元素的值序列化成对象

    function serializeObject(form){ var o={}; $.each(form.serializeArray(),function(index){ if(o[this['n ...

  9. [iOS 多线程 & 网络 - 1.3] - NSOperation

    A.NSOperation的基本使用 1.NSOperation的作用 配合使用NSOperation和NSOperationQueue也能实现多线程编程 NSOperation和NSOperatio ...

  10. poj3687

    Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9028   Accepted: 2444 De ...