0
votes

I have created web service for my Sitefinity website referring the document https://www.progress.com/documentation/sitefinity-cms/create-a-web-service and I have used OData for all the filters selections etc.

Below is the sample response I get from one of the web services.

{
"@odata.context": " ",
"value": [
{
"Id": "aa981bde-a977-48db-a0ed-69b077e3fsdf",
"Title": "Define: Problem",
"Order": "2"
},
{
"Id": "9e346ada-dde9-4a0f-a025-2004932f4dfg",
"Title": "Pre-Planning",
"Order": "1"
}
]
}

Is there a way I can change the response format of the Sitefinity web services. I would like to get a response like :

{
"code": 200,
"data": "THE RESULT OF THE API",
"message": " ",
"status": "OK"
}

code is the HttpStatusCode, status is the HttpStatus, data is the actual result of the API.

Can anyone please help me with this.

Thanks,

Aiswarya

1
Maybe would be easier to write your own web api and return whatever response you want – Veselin Vasilev
@VeselinVasilev Thanks for your response. I wanted to confirm is there any other better way before writing my own. – Aiswarya R

1 Answers

0
votes

There is no way as of now to hook up somewhere and transform the OData response as an object (e.g. no API).

The cleanest way to achieve this functionality is to try with response filter , that will parse the response, transform it and send it down the wire. At the point you are called - you will be working with Streams, so you will need to:

  1. Get the response as a stream
  2. Parse it
  3. Change it
  4. Serailize it back ot JSON
  5. Write it back to the stream

This, however is a bit simplified:

Response.Filter content is chunked

So to implement a Response.Filter effectively requires only that you implement a custom stream and handle the Write() method to capture Response output as it’s written. At first blush this seems very simple – you capture the output in Write, transform it and write out the transformed content in one pass. And that indeed works for small amounts of content. But you see, the problem is that output is written in small buffer chunks (a little less than 16k it appears) rather than just a single Write() statement into the stream, which makes perfect sense for ASP.NET to stream data back to IIS in smaller chunks to minimize memory usage en route.