Skip to content

Instantly share code, notes, and snippets.

@mapyo
Created November 3, 2014 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapyo/02cdbf68d050334a8369 to your computer and use it in GitHub Desktop.
Save mapyo/02cdbf68d050334a8369 to your computer and use it in GitHub Desktop.
Guzzle3のgetとputのサンプル
<?php
require 'vendor/autoload.php';
use Guzzle\Http\Client;
$settings = parse_ini_file('config/settings.ini');
$client = new Client($settings['base_url']);
$client->setDefaultOption('headers',
array(
'Content-Type' => 'application/json',
'Authorization' => "Bearer ${settings['token']}",
)
);
# get
$response = $client->get(
$settings['api_path'],
null # header だが、setDefaultOptionで既に設定している。
)->send()->json();
var_dump($response);
# 金額を+100円する
$response['product']['price'] += 100;
$response = $client->put(
$settings['api_path'],
null, # header だが、setDefaultOptionで既に設定している。
json_encode($response)
)->send()->json();
var_dump($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment