Change HTTP status code as needed

Hi,
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,
Giovanni

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

Giovanni,

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…

yours,
marc

Thank you, Marc.

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

1 Like

Hi,

you can use TROHttpApiResult:

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

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.

Hi,

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.