Git Product home page Git Product logo

resty.php's Introduction

Resty.php

A simple PHP library for doing RESTful HTTP stuff. Does not require the curl extension.

Installation

Use composer to install Resty:

  1. Install composer into your project:
curl -s https://getcomposer.org/installer | php

Create a composer.json file in your project root:

{
    "require": {
        "resty/resty": "@stable"
    }
}

Install via composer:

php composer.phar install

Example

<?php
require "vendor/autoload.php";

use Resty\Resty;

$resty = new Resty();
$resty->setBaseURL('http://httpbin.org/');
$resp = $resty->get('headers');

echo "\n\$resp['status']:\n";
var_dump($resp['status']);

echo "\n\$resp['headers']:\n";
var_dump($resp['headers']);

echo "\n\$resp['body']:\n";
var_dump($resp['body']);

echo "\n\$resp['body_raw']:\n";
var_dump($resp['body_raw']);

Output

$resp['status']:
int(200)

$resp['headers']:
array(6) {
  ["Access-Control-Allow-Origin"]=>
  string(1) "*"
  ["Content-Type"]=>
  string(16) "application/json"
  ["Date"]=>
  string(29) "Thu, 13 Feb 2014 15:09:33 GMT"
  ["Server"]=>
  string(15) "gunicorn/0.17.4"
  ["Content-Length"]=>
  string(3) "225"
  ["Connection"]=>
  string(5) "Close"
}

$resp['body']:
object(stdClass)#3 (1) {
  ["headers"]=>
  object(stdClass)#4 (5) {
    ["Host"]=>
    string(11) "httpbin.org"
    ["Connection"]=>
    string(5) "close"
    ["Content-Type"]=>
    string(33) "application/x-www-form-urlencoded"
    ["X-Request-Id"]=>
    string(36) "259dfd8e-6a24-4e77-ae83-9ce50c29ea78"
    ["User-Agent"]=>
    string(11) "Resty 0.6.0"
  }
}

$resp['body_raw']:
string(225) "{
  "headers": {
    "Host": "httpbin.org",
    "Connection": "close",
    "Content-Type": "application/x-www-form-urlencoded",
    "X-Request-Id": "259dfd8e-6a24-4e77-ae83-9ce50c29ea78",
    "User-Agent": "Resty 0.6.0"
  }
}"

Coding Standards

For PHP code, I've decided to adopt the PSR-2 standard.

To automatically check against the PSR-2 standard in Sublime Text, you can use the Phpcs package or the SumblimeLinter-phpcs plugin. I use the former at the moment. I have the following in Preferences > Package Settings > PHP Code Sniffer Settings - User:

{
    "phpcs_executable_path": "/usr/local/Cellar/php55/5.5.8/bin/phpcs",
    "phpcs_additional_args": {
        "--standard": "PSR2",
        "-n": ""
    }
}

Generating API docs

  1. Download phpDocumentor.phar into the root project directory:
curl -O http://phpdoc.org/phpDocumentor.phar

Note: we don't install phpDocumentor with composer to avoid the numerous dependencies it introduces into the project

  1. Generate the API docs:
php phpDocumentor.phar -d src/ -t docs/api --template clean

resty.php's People

Contributors

funkatron avatar honzatrtik avatar jasonrhodes avatar lukestokes avatar scoates avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.