Setup

Exposing models via the REST API requires the ride/wra-orm module.

// composer.json

{
  	// ...
  	"ride/wra-orm" : "*"
}

The Ride API can query all models, when they are configured correctly. You'll need to add the option json.api for each of these models. The value of this option should be the endpoint for that model.

<model name="Post">
  	<option name="json.api" value="posts"/>
</model>

The cache should be cleared after adding this option in order to it having effect.

php application/cli.php cc

This model can now be queried via /api/v1/posts.

Filtering

The filter= query parameter allows for filtering the data set. There are four filters available.

  • filter[exact]
  • filter[match]
  • filter[expression]
  • filter[query]

Some examples.

Exact filter:

The exact filter will create a basic equals condition.

GET /api/v1/posts?filter[exact][id]=1

Match filter:

A match filter will match part of a value (LIKE %%).

GET /api/v1/posts?filter[match][title]=lor

Expression filter:

The expression filter takes a query expression the same way the ORM query conditions do.

GET /api/v1/posts?filter[expression]=id=1
GET /api/v1/posts?filter[expression]={author.name}="Erik"

Query filter:

Model API

/api/v1/{type}

Get the entries of a specific model.

/api/v1/{type}

Create a new entry for a specified model.

{
    "data": {
        "type": "posts",
        "attributes": {
            "title": "Foo",
          	"body": "Lorem ipsum dolor sit amet"
        },
        "relationships": {
            "author": {
                "data": {
                    "type": "authors",
                    "id": 1
                }
            }
        }
    }
}

/api/v1/{type}/{id}

Get a specific entry.

/api/v1/{type}/{id}

Edit a specific entry.

{
    "data": {
        "type": "posts",
        "id": 4,
        "attributes": {
            "title": "Bar",
            "body": "Lorem ipsum"
        },
        "relationships": {
            "author": {
                "data": {
                    "type": "authors",
                    "id": 2
                }
            }
        }
    }
}

/api/v1/{type}/{id}

Delete a specific entry.

/api/v1/{type}/{id}/{relationship}

Get an entry's relationship.

// GET /api/v1/posts/4/author

{
    "jsonapi": { ... },
    "links": { ... },
    "data": {
        "type": "authors",
        "id": "2",
        "attributes": {
            "name": "Erik"
        },
        "relationships": {
            // ...
        }
    },
    "included": [ ... ]
}

/api/v1/{type}/{id}/relationships/{relationship}

Get meta data of an entry's relationship.

/api/v1/{type}/{id}/relationships/{relationship}

Create a new relationship for an entry.

/api/v1/{type}/{id}/relationships/{relationship}

Edit a relationship of an entry.

/api/v1/{type}/{id}/relationships/{relationship}

Delete an entry's relationship.

Model Meta API

The following calls are used to query meta information of models.

/api/v1/models

Get a collection of all models.

/api/v1/models/{id}

Get meta data of a specific model.

/api/v1/models/{id}/{relationship}

Get a model's relationship.

/api/v1/models/{id}/relationships/{relationship}

Get meta data of a model's relationship.

/api/v1/model-fields/{id}

Get the fields of a specified model.