Code Monkey home page Code Monkey logo

enm-json-api-client's Introduction

JSON API Client

Build Status Coverage Status Total Downloads Latest Stable Version Latest Unstable Version License

This package is abandoned. Please use dogado/json-api-client instead.

Abstract client-side PHP implementation of the json api specification.

It's based on the original creation of the eosnewmedia team and the maintainer Philipp Marien.

Installation

composer require chris-doehring/enm-json-api-client

It's recommended to install guzzlehttp/guzzle version ^7.0 as http-client and http-interop/http-factory-guzzle for PSR-17 compatible factories.

composer require guzzlehttp/guzzle http-interop/http-factory-guzzle

You can also use any other HTTP client which implements PSR-18.

Usage

First you should read the docs at chris-doehring/enm-json-api-common where all basic structures are defined.

Your API client is an instance of Enm\JsonApi\Client\JsonApiClient, which requires a PSR-18 HTTP client (Psr\Http\Client\ClientInterface) to execute requests.

$client = new JsonApiClient(
    'http://example.com/api',
    $httpClient, // instance of Psr\Http\Client\ClientInterface
    $uriFactory, // instance of Psr\Http\Message\UriFactoryInterface
    $requestFactory, // instance of Psr\Http\Message\RequestFactoryInterface
    $streamFactory, // instance of Psr\Http\Message\StreamFactoryInterface
    new Serializer(),
    new Deserializer()
);

$request = $client->createGetRequest(new Uri('/myResources/1')); // will fetch the resource at http://example.com/api/myResources/1
$request->requestInclude('myRelationship'); // include a relationship

$response = $client->execute($request);

$document = $response->document();
$myResource = $document->data()->first(); // the resource fetched by this request
$myIncludedResources = $document->included()->all(); // the included resources fetched with the include parameter

enm-json-api-client's People

Contributors

bogomolov-dev avatar chris-doehring avatar madkatze avatar pmarien avatar richgerdes avatar tgroszewski avatar

enm-json-api-client's Issues

HttpException should contain complete document and PSR response

The JsonApiClient::execute method has the parameter to automatically create a Enm\JsonApi\Exception\HttpException in case an error get's returned. Unfortunately, after creation of the exception, the document and PSR reponse context is gone. Both should be part of the exception instance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.