Code Monkey home page Code Monkey logo

op-restclient's Introduction

OP-Restclient

OOP - Object-oriented programming
PHP
REST-Client

A generic REST API client for PHP using objects to compose requests. This is based on and extends the excellent tcdent/php-restclient.

https://github.com/ocjojo/op-restclient (c) 2017 Lukas Ehnle [email protected]

Installation

$ composer require ocjojo/op-restclient

Basic Usage

$api = new OPRestclient\Client([
    'base_url' => "https://jsonplaceholder.typicode.com"
]);
// GET https://jsonplaceholder.typicode.com/posts/1?param_1=hello&param_2=world
$result = $api->posts->{1}->get([
	'param_1' => "hello",
	'param_2' => "world"
]);
if($result->info->http_code == 200)
    var_dump($result->decode_response());

Options for the client

See the documentation of tcdent/php-restclient for the configurable options. OPRestClient extends tcdent's RestClient, so all options and methods apply equally.

Standard Parameters

You are able to set standard parameters for consecutive requests to the same endpoint, e.g. if you want access data at an endpoint with paging. Like so:

$api = new OPRestClient\Client([
    'base_url' => "https://api.twitter.com/1.1", 
    'format' => "json", 
     // https://dev.twitter.com/docs/auth/application-only-auth
    'headers' => ['Authorization' => 'Bearer '.OAUTH_BEARER]
]);

$api->search->tweets['q'] = '#php';
//both results will have the query parameter q set to '#php'
$result = $api->search->tweets->get(['page' => '1']);
$result2 = $api->search->tweets->get(['page' => '2']);

// to delete a standard parameter of a route
unset($api->search->tweets['q']);

// to delete all standard parameters of a route
$api->search->tweets->reset();

Standard Parameters will be set until you unset them manually.

op-restclient's People

Contributors

ocjojo avatar

Watchers

James Cloos avatar  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.