0
votes

I am using Silverstripe Restfulserver and want to make a GET request to get a collection of data objects. For example, /events should return a list of events in some logical order. I see in the docs that you can make a POST call to /[dataobject] and create a new object and /[dataobject]/[id] to GET a specific object but is there not a GET alternative to return a collection? I currently have a events method created on the page controller to return the list, but was wondering if anyone had a more restful way to accomplish this in Silverstripe. Furthermore, is there a way to append params on to the route (/events?start=[date]&end=[date]) and GET a range of dates between the start and end params in a restful manner?

1
I have actually developed a restful api SS3 module github.com/colymba/silverstripe-restfulapi you might find it easier. Still in Dev but the master branch is pretty stable. - colymba
Thanks Colymba. I will take a look. - Todd Valentine
colymba, I apologize if this should be addressed in the issues on Github, but is there a way to get relations using your API? For example, if each event dataobject/model has_one thumbnail, is there a way to get the url of the thumbnail returned in the JSON response? - Todd Valentine
best is to post this on github, but there is an option for embedded records which will give you the full relations records instead of just the ID. And there is an onBeforeSerialize method called on each dataobject that lets you modify what is returned and add properties to the records.... - colymba

1 Answers

2
votes

In order to return a collection, you can just make a GET call to api/v1/[dataobject]/. If you have set the right canView() permissions on the DataObject, you will receive a list of all the DataObject entities of this type.