askedio/laravel-cruddy

This package is abandoned and no longer maintained. No replacement package was suggested.

A JSON API CRUD Package for Laravel 5

dev-master 2016-03-24 03:39 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:06:22 UTC


README

laravel-cruddy

A really simple package that provides a CRUD JSON API for your Laravel 5 application.

Build Status StyleCI Code Climate Codacy Badge Codacy Badge

Installation

Composer: require

composer require askedio/laravel-cruddy:dev-master

Providers: config/app.php

Add the Service Provider to your providers array.

'providers' => [
    Askedio\Laravel5ApiController\Providers\GenericServiceProvider::class,
        ...

Model: app/User.php

Add the traits to your Model to enable the Api and Search features. More Details & Options.

class User extends Authenticatable
{

    use \Askedio\Laravel5ApiController\Traits\ModelTrait;
    use \Askedio\Laravel5ApiController\Traits\SearchableTrait;
    ...

Controller: app/Http/Controllers/Api/UserController.php

Create a new controller for your API. More Details & Options.

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Routing\Controller as BaseController;

class UserController extends BaseController
{
    use \Askedio\Laravel5ApiController\Traits\ControllerTrait;
    public $modal = \App\User::class;
}

Routes: app/Http/routes.php

Create a prefixed group for your api and assign the api and jsonapi middleware. More Details & Options.

Route::group(['prefix' => 'api', 'middleware' => ['api', 'jsonapi']], function()
{
  Route::resource('user', 'Api\UserController');
});


Usage

Consume the API using Laravels resource routes, GET, PATCH, POST and DELETE. More Details & Options.

Example

GET /api/user/1
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

{
  "data": {
    "type": "users",
    "id": 1,
    "attributes": {
      "id": 1,
      "name": "Test User",
      "email": "test@test.com"
    }
  },
  "links": {
    "self": "/api/user/1"
  },
  "jsonapi": {
    "version": "1.0",
    "self": "v1"
  }
}



Comments

My goal is a plug-n-play json api for Laravel. You shouldn't need to configure much of anything to enable the api on your models but if you still want advanced features like relations, searching, etc, you get that too.

If you have any comments, opinions or can code review please reach me here or on twitter, @asked_io. You can also follow me on my website, asked.io.

Thank you.

-William