PHP Classes

Crud HTTP PHP Curl Request: Send HTTP requests to perform CRUD operations

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 56 This week: 1All time: 10,587 This week: 42Up
Version License PHP version Categories
curl-http-request 1.0The PHP License5HTTP, PHP 5, Design Patterns
Description 

Author

This package can send HTTP requests to perform CRUD operations.

It provides a HTTP client class that can send HTTP requests to a given Web server using the PHP Curl extension.

The package provides example scripts to demonstrate how to send HTTP requests using the GET, POST, DELETE and PUT methods to send requests to perform the CRUD opearations (Create, Read, Update and Delete).

Picture of Okanlawon Anuoluwapo
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

 

Example

<?php
require_once ( dirname(__DIR__) . '/index.php' );
use
AnuDev\CurlHttpRequest\HttpRequest;

// make a post request
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) :
   
// your post request body
   
$postdata = json_encode($_POST);
   
$req = new HttpRequest(HOST_API."endpoint/", "POST", $postdata, HEADERS);
    try {
       
$response = $req->post();
       
// check for errors
       
if( $req->errors ) throw new Exception($req->errors, 1);
       
// check for additional info
       
if( $req->info !== 201 ) throw new Exception("Error code: ". $req->info, 1);
       
// decode json object to php array
       
$results = json_decode($response, true);
       
// $results['status'] === "Created" => $results['message'] // you could check api response here
        // success response
       
$res = array("status" => true, "success" => $results);
    } catch (\
Throwable $th) {
       
$res = array("status" => false, "error" => $th->getMessage());
    }
   
$req->close(); // close the request
   
echo json_encode($res); // output to json
endif;



Details

curl-http-request

Custom CRUD http request using CURL made with ease

A custom http request developed using PHP

  • Programming Language: PHP
  • Uses CURL
  • No External Package
  • Allows for CRUD Operations: - Methods: (POST, PUT, GET, DELETE)
  • Can be modified to allow PATCH and so on...

Requirements:

  • PHP >=5.3
  • run composer update

Additional Tips:

  • Can be modified by developers
  • It allows and require modification for sending files

Use Case:

  • Examples on how to use: check the requests-samples directory them modify endpoint
  • Modify the index file in the root folder with your Variables like: HOST_API URL
  • Accepts your API Key, Additional Headers, and also allows to make Authenticated requests with your accessToken

See: GET Request Sample in: requests-samples/index.php


  Files folder image Files (993)  
File Role Description
Files folder image.github (1 directory)
Files folder imagerequests-samples (4 files)
Files folder imagesrc (1 file)
Files folder imagevendor (1 file, 8 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:56
This week:1
All time:10,587
This week:42Up