Download the PHP package othercode/rest without Composer

On this page you can find all versions of the php package othercode/rest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package rest

Rest Client

Tests Latest Stable Version License Total Downloads

Rest client to make GET, POST, PUT, DELETE, PATCH, etc.

Installation

To install the package we only have to add the dependency to composer.json file:

And run the following command:

Usage

To use the Rest we only have to instantiate it and configure the params we want. We can establish the configuration accessing to the ->configuration->configure_property, for example to configure the url of the call we only have to set the ->configuration->url parameter like we can see as follows:

or

After this we have to set the type of call and the parameters that we wil use, in this case we are going to perform a GET request to the "posts/1" endpoint:

The rest client will throw a ConnectionException if there are any problem related to the connection.

NOTE: These errors are related to the session cURL, here is the complete list

Methods

The available methods to work with are:

get()

Perform a GET request.

Parameters Type Description
$url String Required. The URL to which the request is made
$data Array Optional. Associative array of data parameters

Return: Response object

head()

Perform a HEAD request.

Parameters Type Description
$url String Required. The URL to which the request is made

Return: Response object (no body)

post()

Perform a POST request.

Parameters Type Description
$url String Required. The URL to which the request is made
$data Array Optional. Associative array of data parameters

Return: Response object

delete()

Perform a DELETE request.

Parameters Type Description
$url String Required. The URL to which the request is made
$data Array Optional. Associative array of data parameters

Return: Response object

put()

Perform a PUT request.

Parameters Type Description
$url String Required. The URL to which the request is made
$data Array Optional. Associative array of data parameters

Return: Response object

patch()

Perform a PATCH request.

Parameters Type Description
$url String Required. The URL to which the request is made
$data Array Optional. Associative array of data parameters

Return: Response object

getMetadata()

Return the metadata of the request.

Return: Array

getError()

Return the last known error.

Return: Error object

getPayloads()

Return an array with the Response and Request objects.

Return: Array

setDecoder()

Set a new Decoder.

Parameters Type Description
$name String Required. The unique name of the decoder.
$decoder String Optional. The class name with namespace of the new decoder.

Return: Rest object

setEncoder()

Set a new Encoder.

Parameters Type Description
$name String Required. The unique name of the encoder.
$encoder String Optional. The class name with namespace of the new encoder.

Return: Rest object

setModule()

Set a new Module.

Parameters Type Description
$name String Required. The unique name of the module.
$module String Required. The class name with namespace of the new module.
$hook String Optional. The hook name (after/before) that will trigger the module, 'after' by default.

Return: Rest object

unsetModule()

Unregister a module.

Parameters Type Description
$moduleName String Required. The unique name of the decoder.
$hook String Optional. The hook name (after/before) from where delete the module.

Return: Rest object

addHeader()

Add a new header.

Parameters Type Description
$header String Required. The unique name of the header.
$value String Requires. The value of the header.

Return: Rest object

addHeaders()

Add an array of headers.

Parameters Type Description
$headers String Required. An array of headers.

Return: Rest object

NOTE: We can use the addHeader() and addHeaders() methods with the Rest instance or with the configuration object

is the same as

removeHeader()

Remove a header offset.

Parameters Type Description
$header String Required. The unique name of the header.

Return: Rest object

removeHeaders()

Remove an array of headers.

Parameters Type Description
$headers String Required. An array of headers to remove.

Return: Rest object

Modules

This package allow you to create modules to perform task before and after the request. To create a new module we only have to use this template:

IMPORTANT: Any module MUST extends BaseModule

The only method that is mandatory is ->run(), this method execute your custom code of the module.

Once we have our module we can register it with the ->setModule() method. This method needs three parameters, the first one is the name of the module, the second one is the complete namespace of the module, and the third one is the hook name for our module, it can be "before" and "after" depends on when we want to launch our module.

For "before" modules you can use all the properties of the Request object.

For "after" modules you can use all the properties of the Response object.

All modules are executed in the order that we register them into the Rest client, this also affect to Decoders and Encoders.

Decoders

A decoder is a kind of module that allows you to automatically decode de response in xml or json, to use them we only have to set the decoder we want with the ->setDecoder() method:

The default allowed values for this method are: json, xml and xmlrpc. All the decoders are always executed in the "after" hook.

Custom Decoders

To create a new decoder we only have to use this template:

Like in modules, we have the Response object available to work. The $contentType property is the content-type that will trigger the decoder, in the example above all responses with content-type "application/json" will trigger this decoder.

Quick Calls

We can do quick calls using the \OtherCode\Rest\Payloads\Request::call() method. This static method returns a Rest instance, so we can use all the methods from it.

Complete Example


All versions of rest with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.33
ext-curl Version *
ext-xmlrpc Version *
ext-simplexml Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package othercode/rest contains the following files

Loading the files please wait ....