Download the PHP package nidux/niduxrest-php without Composer

On this page you can find all versions of the php package nidux/niduxrest-php. 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 niduxrest-php

NiduxRest for PHP 8.1+ (based on Unirest from Kong)

This is a fork from Unirest that I try to keep it updated as possible. The main idea is to continue with the idea of something quick and simple as originally made by Mashape.

For PHP versions like 8.0 and below, keep using v1.0.5.

Notable changes

Breaking changes

Requirements

Documentation

I will keep most of the original documentation for simplicity, I will update the example as I begin making improvements

Installation

Using Composer

To install unirest-php with Composer, just add the following to your composer.json file:

or by running the following command:

Usage

Creating a Request

So you're probably wondering how using Niduxrest makes creating requests in PHP easier, let's look at a working example:

PAY ATTENTION HERE: You cannot access the properties directly anymore

JSON Requests (application/json)

A JSON Request can be constructed using the Niduxrest\Request\Body::prepareJson helper:

Notes:

Form Requests (application/x-www-form-urlencoded)

A typical Form Request can be constructed using the Niduxrest\Request\Body::prepareForm helper:

Notes:

Multipart Requests (multipart/form-data)

A Multipart Request can be constructed using the Niduxrest\Request\Body::prepareMultiPart helper:

Notes:

Multipart File Upload

simply add an array of files as the second argument to to the prepareMultiPart helper:

If you wish to further customize the properties of files uploaded you can do so with the Niduxrest\Request\Body::prepareFile helper:

Note: we did not use the Niduxrest\Request\Body::multipart helper in this example, it is not needed when manually adding files.

Custom Body

Sending a custom body such rather than using the Niduxrest\Request\Body helpers is also possible, for example, using a serialize body string with a custom Content-Type:

Authentication examples

Bearer token authentication

For simplicity, there is a new method to set a bearer token to the Request

Basic authentication
Using the mashape key for their services (you need to get the key first)

The third parameter, which is a bitmask, will Niduxrest which HTTP authentication method(s) you want it to use for your proxy authentication.

If more than one bit is set, Niduxrest (at PHP's libcurl level) will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. For some methods, this will induce an extra network round-trip.

Supported Methods

Method Description
CURLAUTH_BASIC HTTP Basic authentication. This is the default choice
CURLAUTH_DIGEST HTTP Digest authentication. as defined in RFC 2617
CURLAUTH_DIGEST_IE HTTP Digest authentication with an IE flavor. *The IE flavor is simply that libcurl will use a
special "quirk" that IE is known to have used before version 7 and that some servers require the client to use.*
CURLAUTH_NEGOTIATE HTTP Negotiate (SPNEGO) authentication. as defined in RFC 4559
CURLAUTH_NTLM HTTP NTLM authentication. A proprietary protocol invented and used by Microsoft.
CURLAUTH_NTLM_WB NTLM delegating to winbind helper. Authentication is performed by a separate binary application. *
see libcurl docs for more info*
CURLAUTH_ANY This is a convenience macro that sets all bits and thus makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure.
CURLAUTH_ANYSAFE This is a convenience macro that sets all bits except Basic and thus makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure.
CURLAUTH_ONLY This is a meta symbol. OR this value together with a single specific auth value to force libcurl to probe for un-restricted auth and if not, only that single auth algorithm is acceptable.

Previous versions of Niduxrest support Basic Authentication by providing the username and password arguments:

This has been deprecated, and will be completely removed in v.2.0 please use the Niduxrest\Request::auth() method instead

Cookies

Set a cookie string to specify the contents of a cookie header. Multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")

Set a cookie file path for enabling cookie reading and storing cookies across multiple sequence of requests.

$cookieFile must be a correct path with write permission.

Request Object

You can send a request with any standard or custom HTTP Method present on the Method enum:

Response Object

Upon recieving a response, Niduxrest returns a Response Object, this object will have the following getters available.

Advanced Configuration

You can set some advanced configuration to tune Niduxrest-PHP:

Custom JSON Decode Flags

Niduxrest uses PHP's JSON Extension for automatically decoding JSON responses. sometime you may want to return associative arrays, limit the depth of recursion, or use any of the customization flags.

To do so, simply set the desired options using the setJsonOpts request method:

Timeout

You can set a custom timeout value (in seconds):

Proxy

Set the proxy to use for the upcoming request.

you can also set the proxy type to be one of CURLPROXY_HTTP, CURLPROXY_HTTP_1_0, CURLPROXY_SOCKS4 , CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A, and CURLPROXY_SOCKS5_HOSTNAME.

check the cURL docs for more info.

Proxy Authenticaton

Passing a username, password (optional), defaults to Basic Authentication:

The third parameter, which is a bitmask, will Niduxrest which HTTP authentication method(s) you want it to use for your proxy authentication.

If more than one bit is set, Niduxrest (at PHP's libcurl level) will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. For some methods, this will induce an extra network round-trip.

See Authentication for more details on methods supported.

Default Request Headers

You can set default headers that will be sent on every request:

You can set default headers in bulk by passing an array:

You can clear the default headers anytime with:

Default cURL Options

You can set default cURL options that will be sent on every request:

You can set options bulk by passing an array:

You can clear the default options anytime with:

SSL validation

You can explicitly enable or disable SSL certificate validation when consuming an SSL protected endpoint:

By default is true.

Utility Methods


All versions of niduxrest-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-curl 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 nidux/niduxrest-php contains the following files

Loading the files please wait ....