Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factory methods for DocumentClient, ResponseParser and DocumentParser #79

Merged
merged 4 commits into from
Sep 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,20 @@ php artisan vendor:publish --provider="Swis\JsonApi\Client\Providers\ServiceProv

## Getting started

You can simply require the [DocumentClient](#documentclient) as a dependency and use it in your class.
Alternatively, you can create a repository based on `\Swis\JsonApi\Client\Repository` and use that as a dependency:
You can simply create an instance of [DocumentClient](#documentclient) and use it in your class.
Alternatively, you can create a [repository](#repository).

``` php
use Swis\JsonApi\Client\Repository
use Swis\JsonApi\Client\DocumentClient;

class BlogRepository extends Repository
{
protected $endpoint = 'blogs';
}
$client = DocumentClient::create();
$document = $client->get('https://cms.contentacms.io/api/recipes');

$repository = app(BlogRepository::class);
$document = $repository->all();
if ($document->hasErrors()) {
// do something with errors
} else {
$blogs = $document->getData();
/** @var \Swis\JsonApi\Client\Collection&\Swis\JsonApi\Client\Item[] $collection */
bbrala marked this conversation as resolved.
Show resolved Hide resolved
$collection = $document->getData();

foreach ($collection as $item) {
// Do stuff with the items
}
```

Expand Down