Skip to content

Commit

Permalink
api and headless update
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jul 25, 2018
1 parent 1cd9b7d commit 52c5739
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
38 changes: 3 additions & 35 deletions docs/guide/concept-headless.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,11 @@ In order to see the API Users menu make sure to use luya-admin module in version

## Make calls

In order to make calls to the LUYA Admin APIs you can either use your own library or the [LUYA headless client](https://github.com/luyadev/luya-headless) which provides a very easy to use wrapper. The headless client will be continuously developed in order to match the changing needs of a true headless system.
**Read the [LUYA Headless client documentation](https://luya.io/packages/luyadev--luya-headless) in order to see how to make calls!**

Example usage with the client library:
To extend, improve or speed up your APIs, take a look at [[ngrest-api.md]] guide section.

```php
use luya\headless\Client;

// build client object with token and server infos
$client = new Client('API_TOKEN', 'http://localhost/luya-kickstarter/public_html/admin');

// create get request for `api-admin-lang` endpoint
$request = $client->getRequest()->setEndpoint('api-admin-lang')->get();

// if successfull request, iterate over language items from `api-admin-lang` endpoint
if ($request->isSuccess()) {
foreach ($request->getParsedResponse() as $item) {
var_dump($item);
}
}
```

Using API wrappers (above example as short hand wrapper):

```php
use luya\headless\Client;
use luya\headless\endpoints\ApiAdminLang;

// build client object with token and server infos
$client = new Client('API_TOKEN', 'http://localhost/luya-kickstarter/public_html/admin');

// run the pre-built ActivQuery for the `api-admin-lang` endpoint
foreach (ApiAdminLang::find()->all($client) as $item) {
var_dump($item);
}
```

## Options
## Additional Configuration

If you build a website with the LUYA CMS but use the headless client to render the content, you may want to configure the preview url to point to your headless page.

Expand Down
35 changes: 34 additions & 1 deletion docs/guide/ngrest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,37 @@ In the traditional way you would have to run the action `actionComments` like fo
public $apiRules = [
'api-module-news' => ['extraPatterns' => ['GET {id}/comments' => 'comments']]
];
```
```

## Filtering

Sometimes you need to have additional filtering methods for a given API requests. Assuming you'd like filter row for a given where condition, like groups you have to create a Filtering Model and declare the filter model in the API.

Define the filter model:

```php
class MyApiFilter extends \yii\base\Model
{
public $group_id;

public function rules()
{
return [
[['group_id'], 'integer'],
];
}
}
```

Assigne the filter model to the API:

```php
class MyApi extends luya\admin\ngrest\base\Api
{
public $modelClass = 'app\models\Users';

public $filterSearchModelClass = 'app\models\MyApiFilter';
}
```

Now as you have declared the filtering model to the api, this allows you to use the `filter` param, assuming you d like to filter for a given group_id in the users lise there url would like this `my-api-filter?filter[group_id]=1`.

0 comments on commit 52c5739

Please sign in to comment.