SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Return simple document json #121

Closed francisco-andrade closed 8 years ago

francisco-andrade commented 8 years ago

Hi there,

Is there any setting I can do to enable simple json returning on restheart queries?

Even with "hal=c" restheart returns a bigger json than I expected. For example: { "_links" : { "self" : { "href" : "/restheart/persistencia_hml/services?filter={\"name\":\"solr\"}&hal=c"} , "curies" : [ ]} , "_id" : "services" , "_created_on" : "2016-02-22T19:12:36Z" , "_etag" : { "$oid" : "56cb5da446e0fb00099065d3"} , "_collection-props-cached" : false , "_returned" : 1 , "_embedded" : { "rh:doc" : [ { "_links" : { "self" : { "href" : "/restheart/persistencia_hml/services/56c322703b868aca994001fe"}} , "_id" : { "$oid" : "56c322703b868aca994001fe"} , "name" : "solr" , "version" : "4.10"}]}}

I expected to get simple document json as in the mongo shell client:

db.services.find({"name":"solr"}) { "_id" : ObjectId("56c322703b868aca994001fe"), "name" : "solr", "version" : "4.10" }

Is there any setting or parameter to get this return?

Thanks Francisco Andrade

ujibang commented 8 years ago

Hi @chicoandrade ,

RESTHeart 1.x is indeed verbose.

We addressed this on 2.0 (still in beta-1) where you would get:

{ "_embedded" : 
          { "rh:doc" : [ { "_id" : { "$oid" : "56c322703b868aca994001fe" },
            "name" : "solr",
            "version" : "4.10"
          } ] },
  "_returned" : 1
}

this also specifying the np query parameter that excludes collection properties (such as its _etag) from the response. in any case the default hal mode (compact) doesn't return _links and curies anymore.

mkjsix commented 8 years ago

Hi @chicoandrade, have you tried the 2.0.0 beta release about this?

francisco-andrade commented 8 years ago

Hi @mkjsix , no, I haven't. I was expecting to get only the rh:doc content on the example showed here by Andrea, but I'll try it

francisco-andrade commented 8 years ago

Just tested the 2.0.0 beta and the return had a bit more data than I expected: { "_id": "services", "_created_on": "2016-02-22T19:12:36Z", "_etag": { "$oid": "56cb5da446e0fb00099065d3" }, "_returned": 1, "_embedded": {"rh:doc": [{"_id": {"$oid": "56c322703b868aca994001fe"},"name": "solr","version": "4.10"}]} }

It would be great to have an even simpler option other than hal=c returning only the rh:doccontent that usually returns on the mongodb shell client. {"_id": {"$oid": "56c322703b868aca994001fe"},"name": "solr","version": "4.10"}

ujibang commented 8 years ago

@chicoandrade

I understand your point, however we chose HAL as representation format because it's simple, elegant and standardized.

In HAL, embedded resources goes into the _embedded property.