# Using \`callWithRequest\` inside a controller

**URL:** <https://discuss.elastic.co/t/using-callwithrequest-inside-a-controller/49611>\
**Category:** Kibana\
**Created:** [May 10, 2016, 5:40am UTC](https://discuss.elastic.co/t/using-callwithrequest-inside-a-controller/49611 "2016-05-10T05:40:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veer\_Shubhranshu\_Shr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/veer_shubhranshu_shr/32/9530_2.png) [@Veer\_Shubhranshu\_Shr](https://discuss.elastic.co/u/Veer_Shubhranshu_Shr)\
**Post date:** [May 10, 2016, 5:40am UTC](https://discuss.elastic.co/t/using-callwithrequest-inside-a-controller/49611/1 "2016-05-10T05:40:37Z")

</div>

Hi Kibana Team,

I am working on developing a custom visualization plugin for learning purpose.

I have created a below folder structure:

```
> intalledPlugins
   |- JDVisual
         |- public
         | |- jdvisual.js
         | |- jdvisual.css
         | |- jd.html
         | |- aggregation-editor.html
         |- server
         | |- routes.js
         |- index.js
         |- package.json

```

I am following the base code from [`elasticsearch_status`](https://github.com/timroes/elasticsearch_status).

I have configured my `routes.js` same as in [`elasticsearch_status/server/rotes.js`](https://github.com/timroes/elasticsearch_status/blob/master/server/routes.js).

And as per the example, I have added

```
   import api from './server/routes';

```

to `index.js` in order to use `callWithRequest`.

Now in my `jdvisual.js`, I have the below code:

```
// Include our custom CSS (LESS also works)
require('plugins/JDVisual/jdvisual.css');

// Create an Angular module for this plugin
var module = require('ui/modules').get('JDVisual');

// Add a controller to this module
module.controller('JDVisualController', function($scope, $timeout) {
	$scope.$watch('vis.params.jduid',function() {
		var jduid = $scope.vis.params.jduid;
	});
});
// The provider function must return the visualization
function JDProvider(Private) {
	// Load TemplateVisType
	var TemplateVisType = Private(require('ui/template_vis_type/TemplateVisType'));

	// Return a new instance describing this visualization
	return new TemplateVisType({
		name: 'JD Visual', // the internal id of the visualization
		title: 'JD Visual', // the name shown in the visualize list
		icon: 'fa-desktop', // the class of the font awesome icon for this
		description: 'JD Custom Visualization', // description shown to the user
		requiresSearch: false, // Cannot be linked to a search
		template: require('plugins/JDVisual/jd.html'), // Load the template of the visualization
		params: {
			editor: require('plugins/JDVisual/aggregation-editor.html'), // Use this HTML as an options editor for this vis
		}
	});
}
// Register the above provider to the visualization registry
require('ui/registry/vis_types').register(JDProvider);

```

I wish to use `callWithRequest` inside

```
$scope.$watch('vis.params.jduid', function() {
        //How to use callWithRequest Here.
});

```

Is it possible or am I doing something wrong. If this can be achieved then how?

Thanks,

---

<div class="post-metadata">

**Author:** ![BigFunger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bigfunger/32/7323_2.png) [@BigFunger](https://discuss.elastic.co/u/BigFunger)\
**Post date:** [May 10, 2016, 6:45pm UTC](https://discuss.elastic.co/t/using-callwithrequest-inside-a-controller/49611/2 "2016-05-10T18:45:15Z")

</div>

In his example, the code in `elasticsearch_status/server/routes.js` is running on the kibana server, and is not part of the application that is running in the browser. This is code that exposes url endpoints which wrap the access to elasticsearch.

For example [here](https://github.com/timroes/elasticsearch_status/blob/master/server/routes.js#L11) is he is creating a url endpoint at `/api/elasticsearch_status/indices` which he then can call from a controller in angular using the $http service [here](https://github.com/timroes/elasticsearch_status/blob/master/public/app.js#L25).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:53pm UTC](https://discuss.elastic.co/t/using-callwithrequest-inside-a-controller/49611/3 "2017-07-06T13:53:45Z")

</div>


