REST Services return View on Update/Create

rest-api

(Josh Heilmann) #1

Is there anyway to control the View of an object that gets returned after a Create or Update through the REST Services? My main object being returned is associated to another entity that has some very big text fields. I was surprised to see the large text fields being returned after ever UPDATE/CREATE.

What options do I have?

Thanks.


Hide Cuba properties via REST V2 API
(Max Gorbunkov) #3

There are no settings or request parameters that control the view of the returned JSON object. REST API response is the serialized entity that was returned by the DataManager. We’ll discuss and probably will provide an option not to return or limit the JSON for the create/update operations (https://youtrack.cuba-platform.com/issue/PL-10399) in future releases
In your project, you can override the EntitiesControllerManager bean and modify the JSON in the createEntity and updateEntity methods.


(Josh Heilmann) #5

I’ve extended EntitiesControllerManager and overridden some classes and registered it as cuba_EntitiesControllerManager in the spring configuration file. I’ve done this in the web module. I’m getting an error now though: No qualifying bean of type ‘com.haulmont.restapi.common.RestControllerUtils’ available when spring is attempting to load my cuba_EntitiesControllerManager. I’m I overriding it in the wrong module?

Thanks.


(Max Gorbunkov) #6

Things are a little bit more complicated here. Let me explain. If you take a look at the web.xml file, you’ll find that requests to the /rest URLs are served by a separate dispatcher servlet:

<servlet>
    <servlet-name>rest_api</servlet-name>
    <servlet-class>com.haulmont.restapi.sys.CubaRestApiServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

This servlet uses a separate Spring context. Configuration files for the REST spring context are defined by the cuba.restSpringContextConfig application property. So you may do the following:

  1. Override the controller manager class in the web module.
  2. create new rest-web-spring.xml file with the overrriden bean defintiion in the web module
  3. register the rest-web-spring.xml file in the web-app.properties file:
cuba.restSpringContextConfig = +com/company/resttest/rest-web-spring.xml

After that your version of the controller manager will be registered in the same spring context as other REST-releated spring beans.


(Josh Heilmann) #7

In a basic API request to the /entities/ path I’m now seeing a lot of extra fields not specified in the view that I’m sending as a paramenter:
{{baseUrl}}/entities/njuns$Ticket/:entityId?view=ticket-api-view

We are using 6.9.5. Any update on this? Thanks.


(Max Gorbunkov) #8

Hi Josh,
Next time please create a separate topic for the new problem. Can you please provide more information: how does your view looks like and what extra fields are returned in the response?

As for the initial issue (https://github.com/cuba-platform/cuba/issues/691), it is not scheduled to any release yet.