#1 2023-07-23 08:55:01

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

One small suggestion: Return values for interface-based services

In mormot, when the interface-based method returns a value via TrestServerUriContext, can it be wrapped in json format like :
{
  code:errcode,
  msg:'errmsg',
  data/(result):{...  } or [... ]
},
Most Rest servers currently communicate with js clients in a format similar to this

Offline

#2 2023-07-23 14:21:05

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

Re: One small suggestion: Return values for interface-based services

You can put whatever JSON you want via TrestServerUriContext, so you are free to return such JSON layout.

Offline

#3 2023-07-24 01:50:14

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: One small suggestion: Return values for interface-based services

Thank you for your reply.
This is done using method-based services, which do not take advantage of the convenience of interface-based services. Or, in an interface-based service, how do you get the output parameters to be written in such a format?

Offline

#4 2023-07-24 05:44:42

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

Re: One small suggestion: Return values for interface-based services

You can create you own routing class.

Offline

#5 2023-07-24 06:55:38

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: One small suggestion: Return values for interface-based services

At your prompt, I read the source code TrestServerUriContext in detail, and it is indeed possible to override ServiceResultStart and ServiceResultEnd requirements through inherited classes.

Thanks again for the tip.

Offline

#6 2023-07-24 06:59:16

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: One small suggestion: Return values for interface-based services

My English is poor, most of these contents are written with the help of translation software, some descriptions may not be accurate, which will cause trouble to you.

Offline

#7 2024-07-05 10:07:12

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: One small suggestion: Return values for interface-based services

By customizing the Routing class, I changed the format of the returned data to meet my requirements in the web client, but if the same interface needs to work in the pascal client, it should not be recognized correctly. Should there also be a corresponding method in the TRestClientRouting's inheritance class that can customize the data returned by parsing?

Offline

#8 2024-07-06 09:09:55

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

Re: One small suggestion: Return values for interface-based services

I have added a TRestClientRouting.ClientSideInvoked virtual class method
to customize the returned JSON on client side:
https://github.com/synopse/mORMot2/commit/2eff980f

Offline

#9 2024-07-08 01:34:22

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: One small suggestion: Return values for interface-based services

Thank you for your great work!
  I read the source code and in the new method you added: in the InternalInvoke function of the mormot.soa.client unit, when the clientSideInvoked method is invoked in the DoClientCall method, should the parameter "send" be "resp"?

Offline

#10 2024-07-08 06:11:37

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

Re: One small suggestion: Return values for interface-based services

Of course, you are right.

Please try with
https://github.com/synopse/mORMot2/commit/40b4f571

Offline

Board footer

Powered by FluxBB