Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing issue with PUT vs POST for insert and update

  • Loading branch information...
commit 70d98bf14857ca11323b17f3e07b04e3e393e06c 1 parent c576b5f
@jwage jwage authored
View
4 README.markdown
@@ -20,7 +20,7 @@ Now we can change some properties of that person:
Once we're done we can simply save it and the appropriate REST call will be made:
- $person->save(); // POST http://api.people.com/person/1.xml (name=Jonathan H. Wage)
+ $person->save(); // PUT http://api.people.com/person/1.xml (name=Jonathan H. Wage)
## Client
@@ -67,7 +67,7 @@ execute it, transform the response and hydrate the results to your PHP objects.
$person = new Person();
$person->setName('Jonathan H. Wage');
- $person->save(); // PUT http://api.people.com/person.xml (name=Jonathan H. Wage)
+ $person->save(); // POST http://api.people.com/person.xml (name=Jonathan H. Wage)
We can retrieve that person again now:
View
2  lib/Doctrine/REST/Client/Entity.php
@@ -83,7 +83,7 @@ public function save($action = null)
{
$parameters = $this->toArray();
$exists = $this->exists();
- $method = $exists ? Client::POST : Client::PUT;
+ $method = $exists ? Client::PUT : Client::POST;
$id = $exists ? $this->getIdentifier() : null;
$path = $this->generateUrl(get_defined_vars());
return self::$_manager->execute($this, $path, $method, $parameters, $action);
View
8 tests/Doctrine/Tests/REST/ClientTest.php
@@ -43,7 +43,7 @@ public function testInsert()
$this->assertEquals(1, $test->getId());
$this->assertEquals('http://api.people.com/article.xml', $this->client->last['url']);
- $this->assertEquals('PUT', $this->client->last['method']);
+ $this->assertEquals('POST', $this->client->last['method']);
}
public function testUpdate()
@@ -55,7 +55,7 @@ public function testUpdate()
$this->assertEquals('test', $test->getTitle());
$this->assertEquals('http://api.people.com/article/1.xml', $this->client->last['url']);
- $this->assertEquals('POST', $this->client->last['method']);
+ $this->assertEquals('PUT', $this->client->last['method']);
}
public function testDelete()
@@ -201,10 +201,10 @@ public function execute(Request $request)
$this->last = get_defined_vars();
if ($url === 'http://api.people.com/article.xml') {
- if ($method === Client::PUT)
+ if ($method === Client::POST)
{
return array('id' => 1, 'title' => 'test');
- } else if ($method === Client::POST) {
+ } else if ($method === Client::PUT) {
return $parameters;
} else if ($method === Client::GET) {
return array(
View
4 tests/Doctrine/Tests/REST/FunctionalTest.php
@@ -130,7 +130,7 @@ public function execute(Request $request)
}
// PUT api/user.xml (insert)
- if ($method === 'PUT' && preg_match_all('/api\/' . $this->name . '.xml/', $url, $matches)) {
+ if ($method === 'POST' && preg_match_all('/api\/' . $this->name . '.xml/', $url, $matches)) {
return $this->execServer($request, array(
'_method' => $method,
'_format' => $responseType,
@@ -141,7 +141,7 @@ public function execute(Request $request)
// POST api/user/1.xml (update)
- if ($method === 'POST' && preg_match_all('/api\/' . $this->name . '\/([0-9]).xml/', $url, $matches)) {
+ if ($method === 'PUT' && preg_match_all('/api\/' . $this->name . '\/([0-9]).xml/', $url, $matches)) {
return $this->execServer($request, array(
'_method' => $method,
'_format' => $responseType,
Please sign in to comment.
Something went wrong with that request. Please try again.