srikant-kumar/simple-http-request

Use this package for making simple & complex http request

1.3.1 2023-08-26 05:08 UTC

This package is auto-updated.

Last update: 2024-10-26 07:47:07 UTC


README

The "Simple HTTP Request" class in PHP offers a user-friendly solution for making versatile server-to-server requests without requiring intricate knowledge of the CURL library. This class streamlines the process by providing a range of convenient methods, eliminating the need for directly dealing with CURL.

With this class, developers can effortlessly initiate HTTP requests, regardless of their type, by abstracting away the complexities of CURL. Whether you need to perform GET, POST, PUT, or DELETE requests, this class has you covered. Its intuitive interface empowers developers to communicate with remote servers without delving into the intricate details of the underlying protocol.

By utilizing the "Simple HTTP Request" class, you can focus on the core functionality of your application while leaving the intricacies of HTTP communication to the class itself. This improves code readability, reduces development time, and minimizes potential errors that might arise from manually handling CURL operations.

In summary, the "Simple HTTP Request" class simplifies and enhances the process of sending HTTP requests in PHP, offering a collection of convenience methods that abstract the complexities of CURL. This class is a valuable tool for any developer aiming to streamline server-to-server communication while maintaining a clean and efficient codebase.

How to Use It ?

Method 1 : Direct Usage

  1. Take Pull From : https://github.com/srikant-kumar/simple-http-request
  2. Create Folder in your project with [FOLDER_NAME_YOU_WANT] copy all files into that.
  3. Follow the below code for refrence
<?php
require './FOLDER_NAME_YOU_WANT/src/Httprequest.php';

use Httprequest\Httprequest;
//---This Sample Code For POST Request
$request = new Httprequest('https://example.com');
$post_data = [
	'key1' => $value1,
	'key2' => $value2,
	'key3' => $value3,
];
$request_header = [
	'Authorization' => 'Bearer e5e87a27-3a33-4e03-b3c5-e31d82fdc2f3',
	'x-api-key' => 'mf2yEb92mzcXArFNh2QP7rfpyTS4hgT'
];
//----Options of Http Request
$request->set_content_type('multipart/form-data');
$request->set_request_method('POST');
$request->set_post_data($post_data);
//----Request Header If Needed
$request->set_request_headers($request_header);
$request->run();
$response = $request->get_response();

Method 2 : Using Composer

  1. Run composer command in your project Directory: composer require srikant-kumar/simple-http-request
  2. Include : vendor/autoload.php
  3. Follow the below code for refrence
<?php
require '.vendor/autoload.php';

use Httprequest\Httprequest;
//---This Sample Code For POST Request
$request = new Httprequest('https://example.com');
$post_data = [
	'key1' => $value1,
	'key2' => $value2,
	'key3' => $value3,
];
$request_header = [
	'Authorization' => 'Bearer e5e87a27-3a33-4e03-b3c5-e31d82fdc2f3',
	'x-api-key' => 'mf2yEb92mzcXArFNh2QP7rfpyTS4hgT'
];
//----Options of Http Request
$request->set_content_type('multipart/form-data');
$request->set_request_method('POST');
$request->set_post_data($post_data);
//----Request Header If Needed
$request->set_request_headers($request_header);
$request->run();
$response = $request->get_response();

Set Request Method & Usages

Other method you can use in your request :

Get Response Method & Usages

Other method you can use after completion of a request : Note : Call this method after $request->run();

Why Simple Http Request?

In daily development life we need to call third parties api for the projects. So every time we have to write cURL code that is hard to remember ( I don't know about others but i have problem to remeber the things 😀😀😀 ) that's why i made this package.

It is simple and easy to use.

License

Request is licensed under the MIT