2017 © Pedro Peláez
 

symfony-bundle json-api-bundle

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

image

steffenbrem/json-api-bundle

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

  • Monday, January 22, 2018
  • by steffenbrem
  • Repository
  • 9 Watchers
  • 56 Stars
  • 5,724 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 19 Forks
  • 13 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

JsonApiBundle

Join the chat at https://gitter.im/steffenbrem/JsonApiBundle, (*1)

Integration of JSON API with Symfony 2 (FOSRestBundle), (*2)

Note that this is stil a WIP and should not be used for production!, (*3)

Usage

Coming soon, (*4)

If you want to experiment with this implementation, you can just enable this bundle in your AppKernel and everything should work directly. Try to serialize some annotated php classes and check it out!, (*5)

Configuration reference

mango_json_api:
    show_version_info: true # default
    base_uri: /api # default

Annotations

@Resource

This will define your class as a JSON-API resource, and you can optionally set it's type name., (*6)

This annotation can be defined on a class., (*7)

use Mango\Bundle\JsonApiBundle\Configuration\Annotation as JsonApi;

/**
 * @JsonApi\Resource(type="posts", showLinkSelf=true)
 */
 class Post 
 {
  // ...
 }
Property Default Required Content Info
type ~ No string If left default, it will resolve its type dynamically based on the short class name.
showLinkSelf true No boolean Add self link to the resource

@Id (optional, it defaults to id)

This will define the property that will be used as the id of a resource. It needs to be unique for every resource of the same type., (*8)

This annotation can be defined on a property., (*9)

use Mango\Bundle\JsonApiBundle\Configuration\Annotation as JsonApi;

/**
 * @JsonApi\Resource(type="posts")
 */
 class Post 
 {
    /**
     * @JsonApi\Id
     */
    protected $uuid;
 }

@Relationship

This will define a relationship that can be either a oneToMany or manyToOne. Optionally you can set includeByDefault to include (sideload) the relationship with it's primary resource., (*10)

This annotation can be defined on a property., (*11)

use Mango\Bundle\JsonApiBundle\Configuration\Annotation as JsonApi;

/**
 * @JsonApi\Resource(type="posts")
 */
 class Post 
 {
    // ..

    /**
     * @JsonApi\Relationship(includeByDefault=true, showLinkSelf=false, showLinkRelated=false)
     */
    protected $comments;
 }
Property Default Required Content Info
includeByDefault false No boolean This will include (sideload) the relationship with it's primary resource
showData false No boolean Shows data, which consists of ids of the relationship data
showLinkSelf false No boolean Add self link of the relationship
showLinkRelated false No boolean Add related link of the relationship

Configuration Reference

# app/config/config.yml

mango_json_api:
    show_version_info: true

Example response

GET /api/channels, (*12)

{
    "jsonapi": {
        "version": "1.0"
    },
    "meta": {
        "page": 1,
        "limit": 10,
        "pages": 1,
        "total": 4
    },
    "data": [
        {
            "type": "channels",
            "id": 5,
            "attributes": {
                "code": "WEB-UK",
                "name": "UK Webstore",
                "description": null,
                "url": "localhost",
                "color": "Blue",
                "enabled": true,
                "created-at": "2015-07-16T12:11:50+0000",
                "updated-at": "2015-07-16T12:11:50+0000",
                "locales": [],
                "currencies": [],
                "payment-methods": [],
                "shipping-methods": [],
                "taxonomies": []
            },
            "relationships": {
                "workspace": {
                    "data": {
                        "type": "workspaces",
                        "id": 18
                    }
                }
            }
        },
        {
            "type": "channels",
            "id": 6,
            "attributes": {
                "code": "WEB-NL",
                "name": "Dutch Webstore",
                "description": null,
                "url": null,
                "color": "Orange",
                "enabled": true,
                "created-at": "2015-07-16T12:11:50+0000",
                "updated-at": "2015-07-16T12:11:50+0000",
                "locales": [],
                "currencies": [],
                "payment-methods": [],
                "shipping-methods": [],
                "taxonomies": []
            },
            "relationships": {
                "workspace": {
                    "data": {
                        "type": "workspaces",
                        "id": 18
                    }
                }
            }
        },
        {
            "type": "channels",
            "id": 7,
            "attributes": {
                "code": "WEB-US",
                "name": "United States Webstore",
                "description": null,
                "url": null,
                "color": "Orange",
                "enabled": true,
                "created-at": "2015-07-16T12:11:50+0000",
                "updated-at": "2015-07-16T12:11:50+0000",
                "locales": [],
                "currencies": [],
                "payment-methods": [],
                "shipping-methods": [],
                "taxonomies": []
            },
            "relationships": {
                "workspace": {
                    "data": {
                        "type": "workspaces",
                        "id": 18
                    }
                }
            }
        },
        {
            "type": "channels",
            "id": 8,
            "attributes": {
                "code": "MOBILE",
                "name": "Mobile Store",
                "description": null,
                "url": null,
                "color": "Orange",
                "enabled": true,
                "created-at": "2015-07-16T12:11:50+0000",
                "updated-at": "2015-07-16T12:11:50+0000",
                "locales": [],
                "currencies": [],
                "payment-methods": [],
                "shipping-methods": [],
                "taxonomies": []
            },
            "relationships": {
                "workspace": {
                    "data": {
                        "type": "workspaces",
                        "id": 18
                    }
                }
            }
        }
    ],
    "included": [
        {
            "type": "workspaces",
            "id": 18,
            "attributes": {
                "name": "First Workspace"
            },
            "relationships": {
                "channels": {
                    "links": {
                        "related": "/workspaces/18/channels"
                    }
                }
            }
        }
    ]
}

The Versions

22/01 2018

dev-master

9999999-dev

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steffen Brem

rest jsonapi json-api

08/02 2017

0.2

0.2.0.0

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steffen Brem

rest jsonapi json-api

10/08 2016

0.1.x-dev

0.1.9999999.9999999-dev

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steffen Brem

rest jsonapi json-api

06/05 2016

0.1

0.1.0.0

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steffen Brem

rest jsonapi json-api

12/09 2015

dev-feature/metadata

dev-feature/metadata

Integration of JSON API with Symfony2 using JMS Serializer (FOSRestBundle).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Steffen Brem

rest jsonapi json-api