When accessing examples/rest-client-actions, the following exception is thrown.

GuzzleHttp\Exception\ClientException: Client error: `GET http://localhost:8888/drupal9/rest/node` resulted in a `406 Not Acceptable` response: <!DOCTYPE html> <html lang="zh-hans" dir="ltr"> <head> <meta charset="utf-8" /> <meta name="Generator" content="Dr (truncated...) in GuzzleHttp\Exception\RequestException::create() (line 113 of vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).
GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object) (Line: 204)
GuzzleHttp\Promise\Promise::callHandler(1, Object, NULL) (Line: 153)
GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() (Line: 48)
GuzzleHttp\Promise\TaskQueue->run(1) (Line: 248)
GuzzleHttp\Promise\Promise->invokeWaitFn() (Line: 224)
GuzzleHttp\Promise\Promise->waitIfPending() (Line: 269)
GuzzleHttp\Promise\Promise->invokeWaitList() (Line: 226)
GuzzleHttp\Promise\Promise->waitIfPending() (Line: 62)
GuzzleHttp\Promise\Promise->wait() (Line: 182)
GuzzleHttp\Client->request('GET', 'http://localhost:8888/drupal9/rest/node', Array) (Line: 108)
Drupal\rest_example\RestExampleClientCalls->index() (Line: 63)
Drupal\rest_example\Controller\RestExampleClientController->indexAction()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Original report

When navigating to examples/rest-client-actions, the following error appears:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function get() on null in Drupal\rest_example\Controller\RestExampleClientController->indexAction() (line 54 of modules/contrib/examples/modules/rest_example/src/Controller/RestExampleClientController.php).

Drupal\rest_example\Controller\RestExampleClientController->indexAction()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 57)
Drupal\Core\StackMiddleware\Session->handle() (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 705)
Drupal\Core\DrupalKernel->handle() (Line: 19)
CommentFileSizeAuthor
#8 3186036-8-rest_example-fix-406-get-call.diff752 bytesjvogt

Issue fork examples-3186036

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bogdog400 created an issue. See original summary.

hgneng’s picture

Version: 3.0.2 » 3.0.3

I got the same issue.

And I think this reason is that configFactory is not a member of ControllerBase (it's a member of FormBase). So we should initialize it in constructor.

However, after I fix the issue of configFactory, I get another one:

GuzzleHttp\Exception\ClientException: Client error: `GET http://localhost:8888/drupal9/rest/node` resulted in a `406 Not Acceptable` response: <!DOCTYPE html> <html lang="zh-hans" dir="ltr"> <head> <meta charset="utf-8" /> <meta name="Generator" content="Dr (truncated...) in GuzzleHttp\Exception\RequestException::create() (line 113 of vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).
GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object) (Line: 204)
GuzzleHttp\Promise\Promise::callHandler(1, Object, NULL) (Line: 153)
GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() (Line: 48)
GuzzleHttp\Promise\TaskQueue->run(1) (Line: 248)
GuzzleHttp\Promise\Promise->invokeWaitFn() (Line: 224)
GuzzleHttp\Promise\Promise->waitIfPending() (Line: 269)
GuzzleHttp\Promise\Promise->invokeWaitList() (Line: 226)
GuzzleHttp\Promise\Promise->waitIfPending() (Line: 62)
GuzzleHttp\Promise\Promise->wait() (Line: 182)
GuzzleHttp\Client->request('GET', 'http://localhost:8888/drupal9/rest/node', Array) (Line: 108)
Drupal\rest_example\RestExampleClientCalls->index() (Line: 63)
Drupal\rest_example\Controller\RestExampleClientController->indexAction()
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
jungle’s picture

Version: 3.0.3 » 4.0.x-dev

Reproduced!

jaydee1818’s picture

I'm also experiencing this

apaderno made their first commit to this issue’s fork.

avpaderno’s picture

Component: Action Example » REST Example
avpaderno’s picture

Title: Rest-Client-Actions generates error » Visiting examples/rest-client-actions throws a GuzzleHttp\Exception\ClientException exception
Issue summary: View changes

I fixed the access to the not initialized $configFactory in #3458249: Do not use ControllerBase as parent class for RestExampleClientController.

jvogt’s picture

StatusFileSize
new752 bytes

Apparently this has to do with Drupal dropping support for the Accept header, which this module still uses. Instead, we must set the _format query string argument.

Example: https://example.com/rest/node?_format=json

I've attached a patch that addresses the issue for GET calls in RestExampleClientCalls.php. Note that it doesn't make changes to other HTTP method calls (POST, DELETE, etc). It also doesn't make the controller render correctly for '/examples/rest-client-actions'. That has a bunch of other issues, but at least you'll no longer get the 406 error.

avpaderno’s picture

Status: Active » Reviewed & tested by the community

Tests are failing because #3468407: Add the missing @group annotation to test classes. The other GitLab CI jobs are not failing, so the provided patch is good to go.

  • avpaderno committed c9e13486 on 4.0.x
    Issue #3186036: Visiting examples/rest-client-actions throws a...
    
avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for the patch! The merge request has been merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.