Provides an API wrapper around service style classes

Installs: 1 933

Dependents: 4

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0


1.5.0 2020-06-28 10:30 UTC

This package is auto-updated.

Last update: 2020-12-28 11:32:38 UTC


Latest Stable Version Latest Unstable Version Total Downloads License

Wrap your service APIs in a web layer

Composer Install

composer require symbiote/silverstripe-apiwrapper:~1.0


  • SilverStripe 4.1+


Quick start

Suppose we have a class Symbiote\Watch\WatchService that we want to expose to web requests via /api/v1/watch/{methodname}

First, implement webEnabledMethods, returning an array of methods mapping to the request types that can trigger them, ie

    public function webEnabledMethods()
        return [
            'store' => 'POST',
            'list' => 'GET',

In config;

Name: my_webservices
      watch: 'WatchServiceApiController' # The name of an injector service

  WatchServiceApiController: # Referenced by above
    class: Symbiote\ApiWrapper\ServiceWrapperController
      service: %$Symbiote\Watch\WatchService

Additional Options

The return of webEnabledMethods can provide additional information, such as

return [
  'list' => [
    'type' => 'GET', 
    'call' => 'myMethod', // the name of a method on the service to execute 
    'public' => true,
    'match' => 'regex; see below',
    'perm' => 'CMS_Access_etc'


You can define a regex in the 'match' key which allows you to match parameters from the URL substring that is left after the api and method paths are removed.

Note that you must define regex using named capture groups.

For example

'match' => '(?<parent>\d+)'

and the URL


will call the 'list' method with the $parent parameter set to 12.

Note that this must be the full URL match, meaning you should have a capture group for all parts of the URL. In other words, the 'match' string is wrapped in "{^" . $match . "$}" for the regex that actually gets executed.