Managing object's properties with linking and/or resource expansion

126 views
Skip to first unread message

YoruNoHikage

unread,
Jul 11, 2014, 4:48:59 AM7/11/14
to resting-wi...@googlegroups.com
I'm new to REST and was wondering how to deal with properties that are objects.

I read about linking and resource expansion here : https://stormpath.com/blog/linking-and-resource-expansion-rest-api-tips/

But there's few API like Github (I don't know if it's a good example) that expose more properties when you fetch the object than embedded with another.
See user property on https://api.github.com/users/{user}/repos and https://api.github.com/users/{user}

How to do this ? Is this good or bad practice ?

Stepan Anchugov

unread,
Jul 12, 2014, 8:26:20 AM7/12/14
to resting-wi...@googlegroups.com
That's not linking, basically, that's just resource expansion (as it seems to me).

And actually it's OK to use it, though it depends a lot on your use case. For example, the BackboneRelational library for Backbone can be configured so that any embedded objects (or arrays of objects) will be automatically treated as relations, and your client code will have correct relational mappings. Though in some cases you could prefer to fetch these sub-resources manually.

The properties you should expose in embedded resources actually depend on the use case, too. You should figure out what is necessary in each of your cases.

When using FOSRestBundle with JMSSerializer, you can always either configure the serializer so that it fetches and serializes embedded collections into resulting JSON properties:

properties:
        some-property:
            type: Your\Namespace\Entities\SomeEntityToEmbed
In this case serializer shold be configured to serialize the SomeEntityToEmbed, too.

Or you could create an embedded resource action. Doing this is pretty easy with FOSRestBundle, too (see the doc). If you stick with auto-generated routes, that would be pretty easy to implement.

Hope this answers some of your questions.

YoruNoHikage

unread,
Jul 13, 2014, 6:59:39 PM7/13/14
to resting-wi...@googlegroups.com
Thanks for this long answer. I haven't thought that we could do as we want depending on the case.
So, I have to redefine another entity to expose less properties, right ?

I also just saw it's possible to filter properties in the entity via the annotation @Groups in JMS.

Stepan Anchugov

unread,
Jul 14, 2014, 1:38:56 AM7/14/14
to resting-wi...@googlegroups.com
Well, groups is the way to go here, I think. In your index action you use one serializer group, in show action there's another, then you should edit your serializer configuration so that embedded props are only serialized in show action (or maybe you'll want to do it some other way?)

Di majo

unread,
May 8, 2024, 12:29:50 PM5/8/24
to RESTing with Symfony
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages