Giter Site home page Giter Site logo

easy-curl's Introduction

Easy Curl

Status GitHub issues GitHub pull requests GitHub GitHub tag (latest SemVer)


This is a PHP wrapper for cURL

๐Ÿ“ Table of Contents

๐Ÿง About


This project was created to help developers easily interact with the underlying cURL API.

๐Ÿ Getting Started


These instructions will get you a copy of Easy Curl up and running.

Prerequisites

In order to install this package you have to install composer which can be done by following the steps based on your system here.

If you have not done so already run composer init in the root of your project directory, do so now to start using composer. Just follow the prompts as they appear.

Installing

To install Easy Curl run the command below while in your project root.

composer require lowem/easy-curl

Create a new PHP file and add the code below to the top of the file to automatically load in the package as well as any others you may have installed. The use statement prevents you from having to type in the full namespace of the package.

require_once "vendor/autoload.php";
use Lowem\EasyCurl\EasyCurl;

๐ŸŽˆ API Usage

GET Request get(header)

  • header: This is an array of HTTP header fields
    • Example:
      [
        "Content-Type: application/json",
        "Accept: application/json"
      ]

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts");
    try {
      $test->get();
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

POST Request post(postFields, header)

  • postFields: This is the data that you want to send to the API. It can be JSON, XML, an array with key value pairs, etc.
    • Example:
      [
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ]
  • header: This is an array of HTTP header fields
    • Example:
      [
        "Content-Type: application/json",
        "Accept: application/json"
      ]

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts");
    try {
      $data = [
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ];
      $test->post(json_encode($data), [
        "Content-type: application/json; charset=UTF-8",
      ]);
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

PUT Request put(postFields, header)

  • postFields: This is the data that you want to send to the API. It can be JSON, XML, an array with key value pairs, etc.
    • Example:
      [
        "id" => 1,
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ]
  • header: This is an array of HTTP header fields
    • Example:
      [
        "Content-Type: application/json",
        "Accept: application/json"
      ]

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
    try {
      $data = [
        "id" => 1,
        "title" => "foo",
        "body" => "bar",
        "userId" => 1
      ];
      $test->put(json_encode($data), [
        "Content-type: application/json; charset=UTF-8",
      ]);
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

DELETE Request delete()

    Example Usage:

    $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
    try {
      $test->delete();
    } catch (HTTPRequestException $e) {
      echo $e->getCustomMessage();
    }
    print_r($test->getExecMessage());
    
    $test->close();

โœ๏ธ Authors

See also the list of contributors who participated in this project.

easy-curl's People

Contributors

alexslaboratory avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.