Get field value and label for a content type using REST API I need to create a REST API endpoint with GET operation in Drupal 8. The API should return all fields of a given content type. Right now I am only able to fetch the title. 

Also, I am not supposed to use the REST Export option in views module but the expected output is same as what we get using the Views REST Export option. 

This is the code I have written for the get() method and right now only title is being displayed. I want to output the remaining fields as well.

public function get() {
    if (!$this-&gt;currentUser-&gt;hasPermission('access content')) {
        throw new AccessDeniedHttpException();
    }

    $query = \Drupal::entityQuery('node')
      -&gt;condition('status', 1)
      -&gt;condition('type', 'schemes_funds_nav')-&gt;execute();

    $nodes = \Drupal\node\Entity\Node::loadMultiple($query);

    foreach ($nodes as $entity) {
        $result[$entity-&gt;id()] = $entity-&gt;title-&gt;value;
    }

    $response = new ResourceResponse($result);
    $response-&gt;addCacheableDependency($result);

    return $response;
}


Any help is highly appreciated. Thanks in advance.
In the foreach you add just title so it's normal to have only title displayed:
you should populate your array result with the values from your entity, something like:

  foreach ($nodes as $entity) {
    $result[] = [
      'nid' =&gt; $entity-&gt;id(),
      'title' =&gt; $entity-&gt;title-&gt;value,
      'FIELD_NAME_1' =&gt; $entity-&gt;FIELD_NAME_1-&gt;getValue(),
      'FIELD_NAME_2' =&gt; $entity-&gt;FIELD_NAME_2-&gt;getValue(),
       // And so on with other fields.
    ];
  }