Download the PHP package byjg/webrequest without Composer
On this page you can find all versions of the php package byjg/webrequest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download byjg/webrequest
More information about byjg/webrequest
Files in byjg/webrequest
Package webrequest
Short Description A lightweight and highly customized CURL wrapper for making RESt calls using PSR7 implementation and a wrapper for call dynamically SOAP requests.
License MIT
Informations about the package webrequest
Web Request
A lightweight PSR-7 implementation and and highly customized CURL wrapper for making RESt calls.
Main Features
This class implements:
- PSR-7 Request and Response;
- PSR-18 Http Client
- Helper to create Request instances with the most common use cases;
- Wrapper to execute several requests in parallel;
PSR-7 Implementation and basic usage
Since the implementation follow the PSR7 implementation there is no much explanation about the usage.
The key elements are:
- URI - Will define the URI with parameters, path, host, schema, etc
- Request - Will set the request headers and method;
- Response - Will receive the response header, body and status code.
More information about the PSR-7 here.
The implementation to send the request object is defined by the class HttpClient
.
This class follow partially the PSR-18 implementation.
So, once you have a Request instance defined just need to call HttpClient::sendRequest($request);
Basic Usage
Passing arguments
Helper Classes
The WebRequest package has Helper classes to make it easy to create Request instances for some use cases.
Passing a string payload (JSON)
Create a Form Url Encoded (emulate HTTP form)
Create a Multi Part request (upload documents)
Customizing the Http Client
The customizations options are:
HttpClientParallel
You can use the HttpClient to do several differents requests in parallel.
To use this funcionallity you need:
- Create a instance of the HttpClientParallel class
- Add the RequestInterface instance
- Execute
The results will be processed as soon is ready.
Below a basic example:
Mocking Http Client
The class MockClient
has the same methods that HttpClient except by:
- Do not send any request to the server;
- You can add the expected Response object;
- You can collect information from the CURL after submit the request.
Setting the expected response object
Debuging the CURL options
Other methods in the MockClient
The methods below are available after the execution of the method sendRequest()
:
- getCurlConfiguration()
- getRequestedObject()
- getExpectedResponse()
Install
Running Tests
Starting the server
We provide a docker-compose to enable start the test server easily.
Running the integration tests
Stopping the server
Dependencies
All versions of webrequest with dependencies
ext-curl Version *
ext-json Version *
byjg/uri Version ^5.0
psr/http-message Version ^1.0|^2.0
psr/http-client Version ^1.0