Skip to content

brianpilati/restful-api-wrapper-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restful-API-wrapper-php

Build Status

Scrutinizer Code Quality

Code Coverage

A simple php RESTful api wrapper.

Code example

  $restful = new RESTful('https://<yourcompany>.com/<path>/<to>/<resource>', '<token>');
  $restful->post($path, $data);

Default Content-Type

The default Content-Type is application/json

To change the default Content-Type

  $restful->setContentType(<newContentType>);

Default URL Path Configuration and Authentication

The default URL Path is <baseURI>/<paht_to_data>/<token>/

If you need to add a special configuration to the URL path

  $restful->setPathConfiguration(<newPathConfiguration>);

Examples

Firebase needs a .json?auth= format.

  $restful = new RESTful('https://<yourcompany>.com/<path>/<to>/<resource>', '<token>');
  $restful->setPathConfiguration('.json?auth=');
  $restful->post($path, $data);

Header Authentication

To set the authentication in the header request

  $restful->setHeaderProperty('<name_of_property>');

The full header property will be

  '<name_of_property>: <token>'

List of Library Methods

delete($path) 
get($path) 
getHeaderLocation() 
getHeaderResponseCode() 
getResponseBody() 
patch($path, $data) 
post($path, $data) 
put($path, $data) 
setBaseURI($baseURI) 
setContentType($contentType) 
setHeaderProperty($headerProperty) 
setPathConfiguration($pathConfiguration) 
setTimeOut($seconds) 
setToken($token)

Unit Tests

All the unit tests are found in the "/tests" directory.

The RESTful tests can be executed by running the following command:

All Tests

$ phpunit 

Test Groups

$ phpunit --group <groupName> 

Single Test

$ phpunit tests/unit/<file_name.php>

I started with the firebase-php library (https://github.com/ktamas77/firebase-php). Tamas' code is simply amazing! I helped him write the tests and the test stub. I reached out to him to fork and abstract the code but I never received a response.

-- Firebase PHP Class & Client Library --

https://github.com/ktamas77/firebase-php @author Tamas Kalman [email protected]