Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2017 18:52
What would you like to do?
A simple example Drupal Controller with an uncached JsonResponse
namespace Drupal\example\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class ExampleController extends ControllerBase {
public function getJson(Request $request) {
$data = [];
// Do some useful stuff to build an array of data.
return new JsonResponse($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment