Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON API 1.0 support #679

Closed
vlascik opened this issue Oct 8, 2015 · 1 comment
Closed

JSON API 1.0 support #679

vlascik opened this issue Oct 8, 2015 · 1 comment

Comments

@vlascik
Copy link

vlascik commented Oct 8, 2015

I see Dingo requires Fractal 0.12, which doesn't have proper JSON API 1.0 final support. Is there going to be an update to included Fractal soon, or are there any roadblocks?
This is kind of a show stopper for anyone using ember-data & similar, as it messes up without proper 1.0 formatted responses.

@vlascik
Copy link
Author

vlascik commented Oct 9, 2015

nevermind, solved it, it's possible to put
"league/fractal": "dev-master as 0.12.0" to composer.json's require for now.
however, setting json api serializer is rather unintuitive, maybe there should be a more direct way to set and configure it, or maybe there could be an example in docs? I can see I was not the only one that had this problem.

Sample service provider for json api serializer:

<?php namespace App\Providers;
use Dingo\Api\Transformer\Adapter\Fractal;
use Illuminate\Support\ServiceProvider;
use League\Fractal\Manager;
use League\Fractal\Serializer\JsonApiSerializer;

class FractalJsonApiServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
//
    }

    /**
     * Register the application services.
     *
     */
    public function register()
    {

        $this->app->bind('League\Fractal\Manager', function ($app) {
            $fractal = new Manager;
            $baseUrl = config('app.url');
            $serializer = new JsonApiSerializer($baseUrl);
            $fractal->setSerializer($serializer);
            return $fractal;
        });

        $this->app->bind('Dingo\Api\Transformer\Adapter\Fractal', function ($app) {
            $fractal = $app->make('League\Fractal\Manager');
            return new Fractal($fractal, 'include');
        });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant