2017 © Pedro Peláez
 

library base-api

Abstraction for api resources in laravel

image

sedp-mis/base-api

Abstraction for api resources in laravel

  • Wednesday, March 29, 2017
  • by ajcastro
  • Repository
  • 5 Watchers
  • 0 Stars
  • 88 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

SedpMis\BaseApi

Build Status Coverage Status, (*1)

Abstraction for api resources in Laravel. Compatible to use with Laravel 4.2 and 5.*., (*2)

Installation

Use composer to install base-api and dependencies:, (*3)

composer require sedp-mis/base-api

Introduction

The purpose of this repository is to create an abstraction for common use-cases of api resources. It is a good practice to version our api so we will set our base api to api/v1. So in the following api implementations, the example resource to be used is posts., (*4)

Implementation

METHOD URL Description
GET api/v1/posts @index, List of resources
POST api/v1/posts @store, Create or store new resource
GET api/v1/posts/{id} @show, Show resource
`PUT PATCH` api/v1/posts/{id} | @update, Update resource
DELETE api/v1/posts/{id} @destroy, Destroy or delete resource

Notice that @<method> are the same with the controller methods in laravel., (*5)

Advance Implementation for GET methods like @index and @show.

@index and @show

  • Selective Attributes. Resource can be fetched with selective or specific fields or attributes by using query parameter attributes[]. Example:, (*6)

    GET url?attributes[]=id&attributes[]=title
    
  • Relations. Resource can be fetched with eager loaded relations by using query parameter relations[]. Example:, (*7)

    GET url?relations[]=comments&relations[]=labels
    
  • Relations Attributes. Fetched eager loaded relations can also have selective or specific attributes. Example:, (*8)

    GET url?relations[comments][attributes][]=id&relations[comments][attributes][]=text
    

@index

  • Pagination. For list of resources, it is recommended to have it paginated:, (*9)

    GET url?page=1&per_page=100
    

    This example shows that it is currently on the 1st page and showing 100 records per page. Without page parameter, the list will default to all resources to be fetched., (*10)

  • Filtering. It is also handy to filter list by its attributes using filters[attribute][] parameter., (*11)

    • Default:
    GET url?filters[tag][]=cool&filters[tag][]=trending
    
    • Using equals operator (behaves like the default example):
    GET url?filters[tag][equals][]=cool&filters[tag][equals][]=trending
    
    • Using not_equals operator:
    GET url?filters[tag][not_equals][]=bug&filters[tag][not_equals][]=foo
    
  • Searching. It is also possible to search by passing search query parameter., (*12)

    GET url?search[input]=SomeTextToSearch&search[compare][]=title&search[compare][]=description
    
  • Sorting. Sorting can be done by this syntax sort[attribute_1]=asc&sort[attribute_n]=desc. Example:, (*13)

    GET url?sort[title]=asc
    

The Versions

29/03 2017

0.2.x-dev

0.2.9999999.9999999-dev

Abstraction for api resources in laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Arjon Jason Castro

api base-api laravel-api api resources

29/09 2016

dev-develop

dev-develop

Abstraction for api resources in laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Arjon Jason Castro

api base-api laravel-api api resources

29/09 2016

dev-master

9999999-dev

Abstraction for api resources in laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Arjon Jason Castro

api base-api laravel-api api resources

23/09 2016

v0.1.0

0.1.0.0

Abstraction for api resources in laravel

  Sources   Download

MIT

The Requires

 

by Arjon Jason Castro

api base-api laravel-api api resources