2017 © Pedro Peláez
 

symfony-bundle api-wrapper-bundle

API Wrapper Bundle. Consume API's from Symfony

image

franjid/api-wrapper-bundle

API Wrapper Bundle. Consume API's from Symfony

  • Thursday, May 11, 2017
  • by franjid
  • Repository
  • 1 Watchers
  • 5 Stars
  • 50 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 28 % Grown

The README.md

API Wrapper Bundle for Symfony

Build Status Scrutinizer Code Quality Code Coverage, (*1)

The aim of this bundle is to act as a wrapper for any API library you want to use in Symfony. In this case with Guzzle, the most popular PHP HTTP client library., (*2)

It has never been so easy to consume an API than with this bundle., (*3)

What can you find?

Api.php

This is where the encapsulation magic happens., (*4)

It has only one method send that sends the proper request to the API., (*5)

ApiClientFactory.php

Used to create all different API clients. When defined it requires a base uri for the API as a simple string or an array of different url's. In case that an array is given, the factory will choose one of them randomly. This is kind of a basic basic load balancer implemented because of reasons., (*6)

ApiRequest.php

It has to be used to send requests to API's. Using the different methods you will be able to set the request method (GET, POST, etc), set headers, set the endpoint, etc., (*7)

ApiResponse.php

Object returned when successfully calling send method in Api. You can get the response status code, headers or body., (*8)

How to use it

First things first, install package via composer:, (*9)

composer require franjid/api-wrapper-bundle

And add the bundle to your AppKernel.php, (*10)

new \Franjid\ApiWrapperBundle\ApiWrapperBundle(),

Example: adding an API for Xkcd API

You can check a project with example code using the bundle in this repository, (*11)

First step is to define the API Client in your services config file, (*12)

    ApiClientXkcd:
        class: ApiClientXkcd
        factory: [@ApiWrapperBundle.Component.Api.ApiClientFactory, createApiClient]
        arguments:
            - %apiXkcdBaseURI%

That will create the ApiClientXkcd taking the parameter apiXkcdBaseURI and injecting it so we have a base URI., (*13)

apiXkcdBaseURI should be in the format, (*14)

    apiXkcdBaseURI: 'http://xkcd.com/'

Now is time to create the interface, then the service class and add it to your services config file, (*15)

    Service.Api.ApiXkcdServiceInterface:
        class: AppBundle\Service\Api\ApiXkcdService
        arguments:
            - @ApiClientXkcd

At this moment you're ready to go for adding your awesome methods that will call the API., (*16)

The Versions

11/05 2017

dev-master

9999999-dev

API Wrapper Bundle. Consume API's from Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bundle wrapper symfony

14/01 2017

v1.0.0

1.0.0.0

API Wrapper Bundle. Consume API's from Symfony

  Sources   Download

MIT

The Requires

 

The Development Requires

api php bundle wrapper symfony