Commit e50aac47 authored by catch's avatar catch

Issue #2546216 by fortis, edutrul, -enzo-: Return entity object in REST...

Issue #2546216 by fortis, edutrul, -enzo-: Return entity object in REST response body after successful POST
parent a19c7b6a
......@@ -107,9 +107,10 @@ public function post(EntityInterface $entity = NULL) {
$entity->save();
$this->logger->notice('Created entity %type with ID %id.', array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id()));
// 201 Created responses have an empty body.
// 201 Created responses return the newly created entity in the response
// body.
$url = $entity->urlInfo('canonical', ['absolute' => TRUE])->toString(TRUE);
$response = new ResourceResponse(NULL, 201, ['Location' => $url->getGeneratedUrl()]);
$response = new ResourceResponse($entity, 201, ['Location' => $url->getGeneratedUrl()]);
$response->addCacheableDependency($url);
return $response;
}
......
......@@ -361,8 +361,14 @@ public function createAccountPerEntity($entity_type) {
public function assertCreateEntityOverRestApi($entity_type, $serialized = NULL) {
// Note: this will fail with PHP 5.6 when always_populate_raw_post_data is
// set to something other than -1. See https://www.drupal.org/node/2456025.
$this->httpRequest('entity/' . $entity_type, 'POST', $serialized, $this->defaultMimeType);
$response = $this->httpRequest('entity/' . $entity_type, 'POST', $serialized, $this->defaultMimeType);
$this->assertResponse(201);
// Make sure that the response includes an entity in the body and check the
// UUID as an example.
$request = Json::decode($serialized);
$response = Json::decode($response);
$this->assertEqual($request['uuid'][0]['value'], $response['uuid'][0]['value'], 'Got new entity created as response after successful POST over Rest API');
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment