Git Product home page Git Product logo

json-api-common's Introduction

Common interfaces and classes which represent the JSON:API protocol

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

This library contains php classes and interfaces shared between dogado/json-api-server and dogado/json-api-client.

Installation

composer require dogado/json-api-common

Documentation

  1. JsonApiTrait
  2. Resources
    1. Relationships
  3. Attributes and Meta-Informations
  4. Links
  5. Documents
  6. Exceptions and Errors
  7. Request and Response
  8. Model conversion

Credits

This package contains code taken from enm/json-api-common.

License

The MIT License (MIT). Please see License File for more information.

json-api-common's People

Contributors

chris-doehring avatar stixxx2k avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

json-api-common's Issues

Pull additional route parameters out of the JSON API request object

When designing RESTful API's you often want to use url's with additional context like this:

https://api.local/v1/customer/{customerId}/invoice/{invoiceId}

The current JSON API request makes it hard to pull out all named route parameters before the json api request part of the URL starts. There should be an easy to use mechanism to fetch named route parameters from the request, in addition to the existing id method. Without having that feature, one has to find a workaround to bypass the application default request object to the request handler without using the default json api tools.

Model Conversion: Add support for php 8 attributes

The model conversion should support the new php 8 attributes like this:

#[Type("dummy-model")]
class DataModel
{
    #[Id]
    private ?int $id = 123456;

    #[Attribute]
    private ?string $name = 'loremIpsum';

    #[Attribute('values')]
    private ValueObject $valueObject;

    #[Attribute('empty-values')]
    private ?ValueObject $valueObjectNotInitialized = null;

    #[Attribute(ignoreOnNull: true)]
    private ?string $ignoreOnNull = null;
}

The currently used doctrine/annotations will still be supported. We could think about removing annotation support in the next major release v2.0.0. Although we have to drop php 7.4 support in order to have php 8 attributes, we can put this update into version v1.1.0.

Nullable model properties during PATCH request - missing request body context

When the JSON-API server receives a PATCH request, the model converter will automatically fill in the existing payload attributes into the provided model instance. As a result, we have a blank model instance where only those properties are filled, which have been provided with values in the request body.

A PATCH request is designed to modify an existing document partially, but here comes the problem: When trying to work with the converted payload model instance further, we don't know if a property with a null value should be persisted to be null or if it just wasn't set in the request body. We loose the necessarry request payload context. Therefor we require an optional model method, which will provide the information, whether a certain property is intended to be null, because it needs to be "removed", or if it's just blank because it has not been provided. So something equivalent to the php isset function.

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.