Order relationship in RESTful I'm using https://www.drupal.org/project/restful module. I can sort base entity using annotation:

/**
 * Class Things__1_0
 * @package Drupal\restful_thing\Plugin\resource\node\thing
 *
 * @Resource(
 *   name = "things:1.0",
 *   resource = "things",
 *   label = "things",
 *   description = "Export the things with all authentication providers.",
 *   authenticationTypes = TRUE,
 *   authenticationOptional = TRUE,
 *   dataProvider = {
 *     "entityType": "node",
 *     "bundles": {
 *       "course"
 *     },
 *     "sort" = {
 *       "field_weight": "ASC"
 *     },
 *   },
 *   majorVersion = 1,
 *   minorVersion = 0
 * )
 */


But when it comes to relationship, the related data isn't ordered the way I need.

Inside public_fields():

$public_fields['modules'] = array(
  'property' =&gt; 'field_modules',
  'resource' =&gt; array(
    'name' =&gt; 'modules',
    'fullView' =&gt; TRUE,
    'majorVersion' =&gt; 1,
    'minorVersion' =&gt; 0,
    'dataProvider' =&gt; array( //here I'm trying to override dataProvider values
      'sort' =&gt; array(
        'field_weight' =&gt; 'ASC'
      )
    )
  )
);


Is there any way to sort related data?

---edit---

I've also placed "sort" inside the annotation of the modules plugin, but It doesn't have effect too.
I've resolved the sorting problem with sorting data inside the formatter. Here's my code in case someone had similar problems.

&lt;?php

/**
 * @file
 * Contains \Drupal\restful\Plugin\formatter\OrderFormatter.
 */

namespace Drupal\my_module\Plugin\formatter;

use Drupal\restful\Plugin\formatter\FormatterJson;
use Drupal\restful\Plugin\formatter\FormatterInterface;

/**
 * Class OrderFormatter
 * @package Drupal\restful\Plugin\formatter
 *
 * @Formatter(
 *   id = "order_formatter",
 *   label = "ORDER FORMATTER",
 *   description = "Output filtered data",
 *   curie = {
 *     "name": "dis",
 *     "path": "doc/rels",
 *     "template": "/{rel}",
 *   },
 * )
 */
class OrderFormatter extends FormatterJson implements FormatterInterface {

  /**
   * Content Type
   *
   * @var string
   */
  protected $contentType = 'application/json+sort; charset=utf-8';

  /**
   * {@inheritdoc}
   */
  public function render(array $structured_data) {
    $i=0;
    foreach ($structured_data['data'] as $v) {

      $structured_data['data'][$i]['unsortedThings'] = $this-&gt;sortBy($structured_data['data'][$i]['unsortedThings']);
      $i++;
    }
    return drupal_json_encode($structured_data);
  }

  public function sortBy($arr) {
    $results = [];
    foreach ($arr as $k=&gt;$v) {
      $results[$k] = $v['weight']; //this is my sorting field
    }
    asort($results, SORT_REGULAR);

    foreach (array_keys($results) as $key) {
      $results[$key] = $arr[$key];
    }
    $results = array_values($results);
    return $results;
  }

}


You run this formatter by adding header to your request: Accept: application/json+sort; charset=utf-8