Download the PHP package jetcamp/laravel-json-api-client without Composer
On this page you can find all versions of the php package jetcamp/laravel-json-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download jetcamp/laravel-json-api-client
More information about jetcamp/laravel-json-api-client
Files in jetcamp/laravel-json-api-client
Download jetcamp/laravel-json-api-client
More information about jetcamp/laravel-json-api-client
Files in jetcamp/laravel-json-api-client
Vendor jetcamp
Package laravel-json-api-client
Short Description Laravel client for easy access of data from {json:api} APIs
License MIT
Package laravel-json-api-client
Short Description Laravel client for easy access of data from {json:api} APIs
License MIT
Please rate this library. Is it a good library?
Informations about the package laravel-json-api-client
Laravel {json:api} client
Client for easy access of data from {json:api} API. Making requests to API by using PHP HTTP Clients like Guzzle or CURL requires to much code. This package tries to simplify this process, by allowing to get data from API as simply as:
Installation
- Install package
composer require jetcamp\laravel-json-api-client
. - Add service provider
JetCamp\JsonApiClient\Providers\JsonApiServiceProvider::class
toconfig/app.php
- Publish vendor config
php artisan vendor:publish
.
Usage
Getting the client
You can get client in several ways:
- Via Facade
\JetCamp\JsonApiClient\Facades\JsonAPIClient
- Resolving from service container
JetCamp\JsonApiClient\JsonApiClient::class
Making requests
-
get($endpoint)
-
post($endpoint)
- patch($endpoint)
Request options
JsonApiClient::get('users')->withIncludes(['posts'])
- adds query paraminclude=posts
to request URL. See http://jsonapi.org/format/#fetching-includesJsonApiClient::get('users')->withFields(['user'=> ['id','name']])
- adds query paramfields[users]=id,name
. See http://jsonapi.org/format/#fetching-sparse-fieldsetsJsonApiClient::get('users')->withFilters(['users'=>['id'=>['eq'=>1]]])
- adds query paramfilter[users][id][eq]=1
. {json:api} is agnostic about filtering, so you can choose your filtering strategy and pass what ever array you want. See http://jsonapi.org/format/#fetching-filtering.JsonApiClient::get('users')->withQuery(['field'=>1])
- adds query paramfield=1=1
. In theory adding filter, includes, fields and pagination fields should be sufficient.JsonApiClient::limit($limit, $offset)->get('users')
- add result constraints to query param `page[limit]=x&page[offet]=y. See http://jsonapi.org/format/#fetching-paginationJsonApiClient::formData(['name'=>'John'])->post('users')
- define post form data. Form data can contain files i.eJsonApiClient::formData(['image'=> $request->file('image')])->post('photos')
.JsonApiClient::jsonData(['name'=>'John'])->post('users')
- define post JSON data.JsonApiClient::throwException(true)
- whenever non 2xx status code received and appropriate exception is thrown. Set tofalse
if you want handel request response status yourself.JsonApiClient::token($accessToken)->get('users')
- define access token which will be added toAuthorization:Bearer {$accessToken}
header. Note, if there isjwt
session variable there is no need to set token here, because access token will be added to request automatically.
Handling response
Requests will return JsonApiResponse
object. It will contain public variables:
$resopnse->data
- contains response data.$resopnse->meta
- contains meta data of a response.$resopnse->errors
- contains errors data of a response.$resopnse->status
- holds HTTP status code of request. Also it has helper functions$resopnse->meta('count')
- return meta data with keycount
.
Exceptions
//@todo
All versions of laravel-json-api-client with dependencies
PHP Build Version
Package Version
Requires
guzzlehttp/guzzle Version
^7.0.1
woohoolabs/yin Version ^4.3.0
woohoolabs/yang Version ^3.0
woohoolabs/yin Version ^4.3.0
woohoolabs/yang Version ^3.0
The package jetcamp/laravel-json-api-client contains the following files
Loading the files please wait ....