Change HTTP status code as needed

would it be possible to programmatically change HTTP status code for a HttpApi method?

Even if it would be possible to change raising an Exception, I’d also need to return my object using a status code different from the default defined by code annotation.

Thank you very much,

It woud be nice to raise an exception

EROHttpApiException(myHttpCode: integer,  myObject : TROComplexType) 

where myObject could be JSon serialized to create a message returned to client with myHttpCode status.

How can I simply serialize using RoSdk?

Thank you


my apologies for the delay; unfortunately part of our team if off today and tomorrow, for local holidays, so it might be until Wednesday to have an answer for this…


Thank you, Marc.

meanwhile I created a TROComplexType helper class using TROJSONMessage but, I think, there may be a better solution

1 Like


you can use TROHttpApiResult:

  [ROCustom('HttpApiPath', 'test')]
  function TestMethod(): Binary;
function TMyService.TestMethod(): Binary;
  Result := TROHttpApiResult.Create(HTTP_200_code, id_ContentType_image_jpeg,'',false);
  Result.LoadFromFile(..image file location here..);

see more info here

Thank you Evgeny,

but I’d like to use a TROComplex as HTTPApi result instead of Binary and, for error conditions, raising an Exception using the TROComplex class, too.

The solution I found seems to work for me.

Thank you very much.


you can put your json string to stream and return it …
another solution - use the OnCustomResponseEvent event as described at the OnCustomResponseEvent in a ROSDK Server topic.

here you can manipulate with request/response as you want …

Ok, thank you again.