2017 © Pedro PelĆ”ez
 

library resource

Simple resource and serialization system for application

image

fivelab/resource

Simple resource and serialization system for application

  • Monday, September 4, 2017
  • by ZhukV
  • Repository
  • 1 Watchers
  • 0 Stars
  • 324 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Russia has become a terrorist state.

Ā #StandWithUkraineĀ 

Resource System

Build Status, (*1)

Add functionality for work with resources in you application and serialize this resources to any formats., (*2)

Support formats:, (*3)

Requirements

  • PHP 7.4 or higher

Installation

Add Resource package in your composer.json:, (*4)

{
    "require": {
        "fivelab/resource": "~2.0"
    }
}

Now tell composer to download the library by running the command:, (*5)

```shell script php composer.phar update fivelab/resource, (*6)


Problem ------- More web applications use API (Application Programming Interface) with difference result structures. It's difficult for developers and clients (who use this API) because each developer can return any data (JSON or XML). And in more cases, applications does not support media types and return JSON data with any `Content-Type` header. And in most cases, developers use real entities from database for map to JSON (as an example `symfony/serializer`). This work funny, because one entity in backend application can representation to many resources for clients. As an example: we have `User` entity with more data. If user authorized, we must return all data, but if user not logged, we must return less data (`id` and `avatar` as an example). Yes, more people speak what we have a group system, but what will happen if I say that we should have more than 100 groups? Yes, in large application it's real case. In this library we try to resolve all issue related with API. > Note: we don't speak - `API`, we must speak - `Resource`, > because all operations (create, edit, delete, etc...) are performed on one resource (`Blog` as an example). Solution -------- 1. Full isolate between model in database and resource for representation. Model from database convert to resource via `Assembler`. `Blog -> Assembler -> BlogResource`. By this we can create any resources for one model in database. (For `Blog` as example: `BlogResoure`, `PremiumBlogResoure`, `HotBlogResource`, etc...). We don't use group system for separate, we have a separate assembler for each resource. 2. We full support [media type](https://en.wikipedia.org/wiki/Media_type) (`Content-Type/Accept`). If client accept `json`, we return `json`, if client accept `xml`, we return `xml` (but previously we must configure it ;) ). And - one resource, many formats ;) > Note: in our library we use `symfony/serializer` with custom normalizers and additional functionality. > As result, all you custom normalizers/denormaizers will be normal work with our library. License ------- This library is under the MIT license. See the complete license in library

LICENSE, (*7)


Development ----------- For easy development you can use our `Dockerfile`: ```shell script docker build -t fivelab-resource . docker run -it -v $(pwd):/code fivelab-resource bash

After run docker container, please install vendors:, (*8)

shell script composer install, (*9)

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker., (*10)

Contributors:

Thanks to everyone participating in the development of this Resource library!, (*11)

The Versions

04/09 2017

dev-master

9999999-dev

Simple resource and serialization system for application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitaliy Zhuk

api rest serializer resource hateoas web api

04/09 2017

v1.0.0

1.0.0.0

Simple resource and serialization system for application

  Sources   Download

MIT

The Requires

 

The Development Requires

by Vitaliy Zhuk

api rest serializer resource hateoas web api