Created
November 3, 2014 08:21
-
-
Save mapyo/02cdbf68d050334a8369 to your computer and use it in GitHub Desktop.
Guzzle3のgetとputのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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