Modify REST API response structure

Options
Ashwin
Ashwin Registered Posts: 3 ✭✭✭

Hi Guys,

When we are getting the response payload from the DSS endpoint there are 3 keys mentioned as below -

{

"response":"",

"timing:{},

"apiContext": {}

}

My end point is returning as -

{"status":"", "result":"", "error":""}

is there any way to get pure response from the endopints without adding above 3 keys to the response payload?

Answers

  • Liev
    Liev Dataiker Alumni Posts: 176 ✭✭✭✭✭✭✭✭
    edited July 17
    Options

    Hi @Ashwin

    If you need to modify the response for a client that is dependent on it, you could create a Python function endpoint in addition. The client would query this endpoint instead, and it, in turn, would internally query and reformat the response from the other endpoint (the one you currently use).

    You can see a snippet below of what the Python function endpoint might look like.

    from dataiku.apinode import utils
    
    def do_something(features):
        client = utils.get_self_client()
        some_result = client.predict_record("some_other_model_endpoint", features = features)
        reformatted_result = some_result
        return reformatted_result
  • Ashwin
    Ashwin Registered Posts: 3 ✭✭✭
    Options

    Hey Liev,

    I tried the way you explained but I am facing the below error.

    java.lang.ClassCastException: com.dataiku.lambda.endpoints.pyfunction.PyFunctionEndpointHandler cannot be cast to com.dataiku.lambda.endpoints.predictcommon.PredictionEndpointHandlerBase

    import traceback

    from dataiku.apinode import utils


    def api_py_function(f):
    try:
    client = utils.get_self_client()
    result = client.predict_record("my endpoint name", features=f)
    reformatted_result = result
    return reformatted_result
    except Exception as e:
    return traceback.format.exc()

Setup Info
    Tags
      Help me…