router.yml :
simple_twitter.ajax_controller_get_tweets:
path: '_simple_twitter/tweets/{name}/{number}'
defaults:
_controller: '\Drupal\simple_twitter\Controller\AjaxController::getTweetsForUserAction'
_title: 'getTweetsForUser'
requirements:
_permission: 'access content'
AjaxController.php :
public function getTweetsForUserAction($name, $number = 2){
// some service stuff that fills $results..
$results = $this->requestTwitterAndCache($params, $url, $cid);
return new JsonResponse($results);
}