Jump to:

9525 Posts in 1940 Topics by 1528 members

All other Modules

SilverStripe Forums » All other Modules » RESTfulServer API how to expose a function

Discuss all other Modules here.

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba

Page: 1
Go to End
Author Topic: 619 Views
  • keeny
    Avatar
    Community Member
    48 Posts

    RESTfulServer API how to expose a function Link to this post

    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.

  • keeny
    Avatar
    Community Member
    48 Posts

    Re: RESTfulServer API how to expose a function Link to this post

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

  • SSadmin
    Avatar
    Community Member
    91 Posts

    Re: RESTfulServer API how to expose a function Link to this post

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

    619 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.