PHPackages                             emteknetnz/silverstripe-rest-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. emteknetnz/silverstripe-rest-api

ActiveSilverstripe-vendormodule[HTTP &amp; Networking](/categories/http)

emteknetnz/silverstripe-rest-api
================================

Rest API for Silverstripe

0.1.8(2y ago)8782↑650%1[7 issues](https://github.com/emteknetnz/silverstripe-rest-api/issues)[1 PRs](https://github.com/emteknetnz/silverstripe-rest-api/pulls)MITPHPPHP ^7.4 || ^8.0

Since Oct 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/emteknetnz/silverstripe-rest-api)[ Packagist](https://packagist.org/packages/emteknetnz/silverstripe-rest-api)[ RSS](/packages/emteknetnz-silverstripe-rest-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (3)Versions (10)Used By (0)

Silverstripe REST API
=====================

[](#silverstripe-rest-api)

**NOTE: This module is currently a pre-release. The API and/or behaviour may change as newer pre-release versions are tagged.**

This module allows you to quickly and easily create secure REST API endpoints that can be used for both providing database records as JSON as well as optionally allow data to be updated through the API.

Simply subclass the `RestApiEndpoint` class and define your endpoint with `private static array` configuration.

An endpoint provides data for one DataObject type, for instance `SiteTree`. To provide data for more DataObject types simply add more endpoints.

This module is not intended to replace regular Silverstripe controller endpoints if you endpoint provides non-DataObject data.

These instructions assume you have created a project that have `silverstripe/recipe-cms` in the composer.json as some of the code instructions include the `SiteTree` class. You can still use this module without `silverstripe/recipe-cms` as `silverstripe/framework` is the only requirement, though `silverstripe/versioned` is required for the `publish`, `unpublish` and `archive` actions.

Also a common gotcha, if your dataobject isn't showing in the JSON response then you probably need to add a `canView()` to your dataobject that returns `true`. Alternatively you can simply disable the `canView()` check by setting `CALL_CAN_METHODS` to `CREATE_EDIT_DELETE_ACTION` (which lacks `VIEW`) in your endpoint config.

### Contents:

[](#contents)

- [Installation](#readme-quickstart)
- [Quickstart](#readme-quickstart)
- [Querying data](#readme-querying-data)
    - [Filtering](#readme-filtering)
    - [Sorting](#readme-sorting)
    - [Limiting and offsetting](#readme-limiting-and-offsetting)
- [HTTP requests and status codes](#readme-http-requests)
    - [Generic failure status codes](#readme-http-generic)
    - [OPTIONS](#readme-http-options)
    - [GET](#readme-http-get)
    - [HEAD](#readme-http-head)
    - [POST](#readme-http-post)
    - [PATCH](#readme-http-patch)
    - [DELETE](#readme-http-delete)
    - [PUT](#readme-http-put)
- [Endpoint configuration options](#readme-config)
- [Relations](#readme-relations)
- [Individual fields](#readme-individual-fields)
- [CSRF token](#readme-csrf-token)
- [API token](#readme-api-token)
- [Extension hooks](#readme-extension-hooks)

Installation
-----------------------------------------------------------

[](#installation)

`composer require emteknetnz/silverstripe-rest-api`

Works on both Silverstripe CMS 4 and 5.

Quickstart
-------------------------------------------------------

[](#quickstart)

Copy paste the following code snippets to quickly setup a public readonly endpoint the provides `SiteTree` data.

This assumes that you have an existing project created with `silverstripe/cms` installed so that you have the `SiteTree` class available.

**src/MySiteTreeEndpoint.php**

```
