Search code examples
.net-corekendo-gridocelot

How can I get Kendo grid DataSourceRequest object through Ocelot?


There is an Api Gateway that is configured by ocelot. I want to request to the Api with Kendo object and receive that as a Kendo DataSourceRequest. I just did it in Angular and dot net core Api project and It worked properly. However, in this current project I don't have any idea how can I do that via Ocelot. This is my Api method in this below.

    [HttpGet]
    public ActionResult User_Read([DataSourceRequest] DataSourceRequest request)
    {
        var data = _unitOfWork.Repository<User>().GetAll();
        return Ok(data.ToList().ToDataSourceResult(request, ModelState));
    }

ocelot configuration

{
  "DownstreamPathTemplate": "/api/auth/User_Read/{everything}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "localhost",
      "Port": 9001
    }
  ],
  "UpstreamPathTemplate": "/User_Read/{everything}",
  "UpstreamHttpMethod": [ "get" ]
}

and my client request code is like this:

          read: function (e) {
        if (thisObject.defaultFilter) {
          if (e.data.filter) {
            var filters = e.data.filter.filters;
            var existFilter = filters.filter(function (obj) {
              if (obj.field == thisObject.defaultFilter.field) return true;
            }).lenght > 0;
            if (!existFilter) e.data.filter.filters.push(thisObject.defaultFilter);
          }
          else {
            e.data.filter = { logic: "and", filters: [thisObject.defaultFilter] }
          }
        }

        const params = `${toDataSourceRequestString(e.data)}`;
        // datasource read request
        thisObject.http.get(thisObject.readUrl + "?" + params).subscribe((res) => {
          e.success(res);
        });
      }

You will find it easy to how send request for reading data in dot net core and angular in kendo grid here

Finally I got the solution on my own. The problem was in Ocelot configuration. I will explain as an answer.


Solution

  • I should have replaced "/api/auth/User_Read/{everything}" with "/api/auth/User_Read?{url}" or any name instead of "url" like "everything". The important thing was the "?" for mapping routes in Ocelot.