#1 2021-01-04 20:32:30

zekeriye
Member
Registered: 2016-06-09
Posts: 15

check parameters rules before processing at the service based app

Hi;

I newbie mormot and dephi.
I try to make a service based application.
I neeed to check parameters type and rules before processing
if parameters type is not compactible type send to client some error message instead of 406
if parameters check is pass process requested function?

for example ;

type
  TServiceCalculator = class(TInterfacedObject, ICalculator)
  public
    function Add(n1,n2: integer): integer;
  end;

function TServiceCalculator.Add(n1, n2: integer): integer;
begin
  result := n1+n2;
end;

if a client call add function with string type I want to return to client some text about error.
  But a clent call add function with integer params execute add function and function return result.

How can I do this. Does any body have any idea to solve this problem ?

thanks for all.

Offline

#2 2021-01-05 09:32:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,237
Website

Re: check parameters rules before processing at the service based app

There is already some clue about the wrong parameter in the returned text error, IIRC.

One possibility could be to use a variant parameter, and check the explicit input type.
Or to use a method-based service.
Or to overload TSQLRestServer.OnAfterURI event.

But it is always easier (and safer) to rely on the client to be correct, and reject anything dubious.

Offline

#3 2021-01-05 12:19:30

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: check parameters rules before processing at the service based app

Another option is to create a TSQLRestRoutingREST to be used by the service and override the ExecuteSOAByInterface method to handle the error.

Using this approach, I can send a custom error and messagem on an interface-based service.

However, since you want to validate the type of data, it would be best to use method-based services.

Offline

#4 2021-04-11 10:46:22

JD
Member
Registered: 2015-08-20
Posts: 101

Re: check parameters rules before processing at the service based app

macfly wrote:

Another option is to create a TSQLRestRoutingREST to be used by the service and override the ExecuteSOAByInterface method to handle the error.

Using this approach, I can send a custom error and messagem on an interface-based service.

However, since you want to validate the type of data, it would be best to use method-based services.

@macfly

Would you mind sharing some code showing how you did this? I think it might be a solution for one of my use cases because I also use an interface based service.

THanks,

JD

Offline

Board footer

Powered by FluxBB