diff --git a/src/EntityToJsonApi.php b/src/EntityToJsonApi.php
index a2ca36c..221abab 100644
--- a/src/EntityToJsonApi.php
+++ b/src/EntityToJsonApi.php
@@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\jsonapi\Resource\JsonApiDocumentTopLevel;
 use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
+use Drupal\jsonapi\Routing\Routes;
 use Drupal\jsonapi\Serializer\Serializer;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\RequestStack;
@@ -39,11 +40,11 @@ class EntityToJsonApi {
   protected $resourceTypeRepository;
 
   /**
-   * The request stack.
+   * The master request.
    *
-   * @var \Symfony\Component\HttpFoundation\RequestStack
+   * @var \Symfony\Component\HttpFoundation\Request
    */
-  protected $requestStack;
+  protected $masterRequest;
 
   /**
    * The JSON API base path.
@@ -70,7 +71,7 @@ class EntityToJsonApi {
     $this->serializer = $serializer;
     $this->resourceTypeRepository = $resource_type_repository;
     $this->currentUser = $current_user;
-    $this->requestStack = $request_stack;
+    $this->masterRequest = $request_stack->getMasterRequest();
     assert(is_string($jsonapi_base_path));
     assert($jsonapi_base_path[0] === '/');
     assert(substr($jsonapi_base_path, -1) !== '/');
@@ -121,18 +122,19 @@ class EntityToJsonApi {
    */
   protected function calculateContext(EntityInterface $entity) {
     // TODO: Supporting includes requires adding the 'include' query string.
-    $resource_type = $this->resourceTypeRepository->get(
-      $entity->getEntityTypeId(),
-      $entity->bundle()
-    );
+    $entity_type = $entity->getEntityTypeId();
+    $resource_type = $this->resourceTypeRepository->get($entity_type, $entity->bundle());
     // The overridden resource type implementation of "jsonapi_extras" may
     // return a value containing a leading slash. Since this was initial
     // behavior we won't going to break the things and ready to tackle both
     // cases: with or without a leading slash.
     $resource_path = ltrim($resource_type->getPath(), '/');
-    $path = sprintf('%s%s/%s', $this->jsonApiBasePath, $resource_path, $entity->uuid());
-    $master_request = $this->requestStack->getMasterRequest();
-    $request = Request::create($master_request->getSchemeAndHttpHost() . $master_request->getBaseUrl() . $path, 'GET');
+    $request = Request::create($this->masterRequest->getUriForPath("$this->jsonApiBasePath/$resource_path/{$entity->uuid()}"));
+
+    $request->attributes->set($entity_type, $entity);
+    $request->attributes->set(Routes::RESOURCE_TYPE_KEY, $resource_type);
+    $request->attributes->set(Routes::JSON_API_ROUTE_FLAG_KEY, TRUE);
+
     return [
       'account' => $this->currentUser,
       'resource_type' => $resource_type,
