Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

RESTfulServer API how to expose a function


Go to End


4 Posts   2261 Views

Avatar
keeny

Community Member, 48 Posts

26 November 2010 at 7:28pm

Edited: 26/11/2010 7:33pm

I have a class that I want to access over REST:

<?php

class MyClass extends DataObject {
	static $db = array(
		'Title'=>'Text',
		'Published'=>'Boolean'
	);
	
	static $api_access = true;
	
	function canEdit() { return true; }
	function canView() { return true; }
	function canCreate() { return true; }
	
	function foo() {
		return 'foo';
	}
}

So I can do this totally fine:

http://localhost/api/v1/MyClass/1/

But how do I access a function over REST? I want to be able to access:

http://localhost/api/v1/MyClass/1/foo

But I don't know how. Is this possible?

Cheers,

Barry.

Avatar
keeny

Community Member, 48 Posts

27 November 2010 at 1:50am

Looks like you need to set the static $allowed_actions. I've updated the docs here: http://doc.silverstripe.org/restfulserver#exposing_methods

Avatar
SSadmin

Community Member, 90 Posts

1 December 2010 at 3:52pm

good document, barry.. really happy to see your contribution for community growth.

Avatar
SS_Learner

Community Member, 20 Posts

31 July 2012 at 7:43pm

Hi

I am also working on restfulServer api in Silverstripe 3.
I want to execute my function foo on having the url :
http://localhost/api/v1/MyClass/foo

How can i do that?
Any help appreciated.