#1 2019-06-24 19:07:51

sergiogarciaruso
Member
Registered: 2019-06-21
Posts: 5

Using GET return all or some fields and not just the "ID".

Hi all. I'm new using Mormot and we're testing it. We would like the "GET" command to return all or some fields and not just the "ID" field. For example:

...
  TTemporada = class(TSQLRecord)
  private
    fCode : string;
  published
   property Code : string index 30 read fCode write fCode;
  end;
...

Request: GET http://localhost:8080/root/temporada

Result:
[
    {
        "ID": 1
    },
    {
        "ID": 2
    }
]

And we'd like to get the following:

[
  {
     "ID": 1,
     "CODIGO": "Cod1"
  },
  {
     "ID": 2,
     "CODIGO": "Cod2"
  }
]

Regards,
    Sergio

Offline

#2 2019-06-24 23:29:54

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

Re: Using GET return all or some fields and not just the "ID".

Use method/interface based services instead the default orm implementation.

See:
https://synopse.info/files/html/Synopse … ml#TITL_49

https://synopse.info/files/html/Synopse … ml#TITL_46

Offline

#3 2019-06-25 08:10:05

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

Re: Using GET return all or some fields and not just the "ID".

It works as documented.
See https://synopse.info/files/html/Synopse … #TITLE_259

You can use some optional URI arguments to the ORM REST request - see https://synopse.info/files/html/Synopse … #TITLE_560
But as macfly states, it is NOT the best option, for security reasons.
You would better encapsulate your queries into a service (method-based service or interface-based service), then disable the RESTful ORM on production.

Offline

#4 2019-06-25 14:18:32

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

Re: Using GET return all or some fields and not just the "ID".

Maybe this information should be in the documentation.

Default ORM Rest:
Best for tests or internal usage. Must be disabled for public access.

Interface based services:
Best for Delphi/FPC clients or when the client can follow the rules of the service.

Method bases services:
Best por ajax clients or when the service must follow the rules.

Last edited by macfly (2019-06-25 14:18:55)

Offline

#5 2019-06-25 16:02:50

sergiogarciaruso
Member
Registered: 2019-06-21
Posts: 5

Re: Using GET return all or some fields and not just the "ID".

Thank you for your responses and recommendations. Greetings.

Offline

#6 2019-06-26 07:42:15

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

Re: Using GET return all or some fields and not just the "ID".

@macfly

I have enhanced the documentation to make thinks for more, according to your proposal.
See https://synopse.info/files/html/Synopse … #TITLE_266

Offline

#7 2019-06-26 08:32:30

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Using GET return all or some fields and not just the "ID".

@ab

the link does not scroll the page to the appropriate chapter of the documentation, is it only happening for me?

Offline

#8 2019-06-26 10:06:10

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

Re: Using GET return all or some fields and not just the "ID".

Please try https://synopse.info/files/html/Synopse … l#TITL_204

And ensure you re-load the documentation page in your browser to get its latest content.

Offline

#9 2019-06-26 14:30:50

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

Re: Using GET return all or some fields and not just the "ID".

Thanks @ab for the attention of always.

It was excellent.
This is a question that seems to be recurring in the forum and something that I had some difficulty to understand as well.

PS: And best of all is that everything can be mixed, MVC + Method services + interface services, etc. on the same server.

Offline

#10 2019-06-27 09:58:51

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Using GET return all or some fields and not just the "ID".

ab wrote:

Please try https://synopse.info/files/html/Synopse … l#TITL_204

And ensure you re-load the documentation page in your browser to get its latest content.

Thanks, this link works properly, previous not.

Offline

Board footer

Powered by FluxBB