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. mapreduce优化总结

    集群的优化 1.合理分配map和reduce任务的数量(单个节点上map任务.reduce任务的最大数量) 2.其他配置 io.file.buffer.size hadoop访问文件的IO操作都需要通 ...

  2. Matlab中imshow()函数的使用

    imread() 返回的图像类型是uint8类型, 这时用imshow显示图像的时候, imshow会认为输入矩阵的范围在0-255, 如果imshow的参数为double类型的,那么imshow认为 ...

  3. Tkinter教程之Canvas篇(2)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811888 '''Tkinter教程之Canvas篇(2)''''''9.创建item的tag ...

  4. mysql performance_schema 初探

    mysql  performance_schema 初探: mysql 5.5 版本 新增了一个性能优化的引擎: PERFORMANCE_SCHEMA 这个功能默认是关闭的: 需要设置参数: perf ...

  5. hdu5909-Tree Cutting(树形dp)

    偷偷抄bestcoser上面hnust_zhaozhixuan的代码 = = 因为题解看不懂阿 #include <cstdio> #include <cstring> typ ...

  6. 集群——LVS理论(转)

    原文:http://caduke.blog.51cto.com/3365689/1544229 当单个服务器性能 不能满足日益增多访问流量时,服务器的扩展策略: Scale Up :向上扩展,提升单个 ...

  7. ActiveX控件的Events事件

    http://labview360.com/article/info.asp?TID=10152&FID=165 Active X函式库 对使用LabVIEW作为开发环境的开发人员来说,如果能 ...

  8. HDU 3666 THE MATRIX PROBLEM (差分约束)

    题意:给定一个最大400*400的矩阵,每次操作可以将某一行或某一列乘上一个数,问能否通过这样的操作使得矩阵内的每个数都在[L,R]的区间内. 析:再把题意说明白一点就是是否存在ai,bj,使得l&l ...

  9. js两种创建对象方式

    js创建方法的两种方式 <%@ page language="java" contentType="text/html; charset=ISO-8859-1&qu ...

  10. PHP再学习1——cURL表单提交、HTTP请求和响应分析

    1.前言 最近迷恋WEB方面的技术,虽然自己是一个嵌入式工程师,但是我深知若需要把传感器终端的数据推送至“平台”必然会和WEB技术打交道.在工作中发现嵌入式工程师喜欢 二进制形式的协议,例如MODBU ...