diff --git a/restws.module b/restws.module
index 22e6b47..f185c36 100644
@@ -509,3 +509,35 @@ function restws_terminate_request($status_message = NULL, $message = NULL) {
   drupal_page_footer();
   exit;
 }
+
+function restws_menu_get_item_alter(&$router_item, $path, $original_map) {
+  $resources = &drupal_static(__FUNCTION__);
+  if (!isset($resources)) {
+    $info = array_keys(restws_get_resource_info());
+    foreach ($info as $resource) {
+      $resources[] = $resource . '/%';
+    }
+  }
+  // Check if $router_item path needs an updated loader.
+  if (in_array($router_item['path'], $resources)) {
+    $router_item['load_functions'] = serialize(array(1 => 'restws_resource_load'));
+  }
+}
+
+function restws_resource_load($identifier) {
+  $dot = strpos($identifier, '.');
+
+  if ($dot > 0) {
+    $identifier = substr($identifier, 0, $dot);
+  }
+
+  // Discover the entity type.
+  $path = $_GET['q'];
+  $original_map = arg(NULL, $path);
+
+  $entity_types = entity_get_info();
+  if (array_key_exists($original_map[0], $entity_types)) {
+    $entities = entity_load($original_map[0], array($identifier));
+  }
+  return !empty($entities[$identifier]) ? $entities[$identifier] : FALSE;
+}

