Coder Social home page Coder Social logo

alimranahmed / easyhttp Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 1.0 35 KB

A Laravel HTTP-client to make HTTP request easier and log requests and responses

Home Page: https://packagist.org/packages/alimranahmed/easyhttp

License: Apache License 2.0

PHP 100.00%
laravel5 laravel php7 composer http-client guzzlehttp curlphp

easyhttp's Introduction

EasyHttp

Make Http request easily and log the request and response in Laravel's default log(/storage/logs).

This Laravel 5 HTTP-client package to make HTTP request easier. It's a wrap on Guzzle HTTP client and cURL that simplify the common requests. We can use Guzzle or cURL whatever we want on run time of this package.

Installation

Run the following command in your terminal while you are at the root of your project directory:

composer require alimranahmed/easyhttp

That's all!

Usages

By default all the request is made using Guzzle.

<?php
//For GET request
$response = Http::get('www.example.com/get');
 
//For POST Request
$data = ['key' => 'value'];
$headers = ['Content-Type' => 'application/json'];
$response = Http::post('www.example.com/post', $data, $headers);
 
//For PUT request
$data = ['key' => 'value'];
$headers = ['Content-Type' => 'application/json'];
$response = Http::put('www.example.com/put', $data, $headers);
 
//For DELETE request
$response = Http::delete('www.example.com/delete');
 
//To Retrieve the response status, header and body
$response->getStatusCode(); //for status code
$response->getHeaders(); //for headers
$response->contents; //for body

To make any request using cURL we can simply use the using() method as below:

<?php
Http::using('curl')->get('www.example.com/get');

License

This package is licensed under Apache License, Version 2.0

easyhttp's People

Contributors

alimranahmed avatar nlohmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

skyformat99

easyhttp's Issues

A Crucial issue reported from reddit about cURL client of this package

Skimming it, at least for cURL, if the first supplied header isn't "Content-Type" => "application/json" then it won't json_encode() during POST.
And it won't ever do it for PUTs.
And might have a problem with empty data arrays that should become an empty Dict rather than List (e.g. instead wants the output of json_encode( (object) NULL )).
Also it might be desired to be able to json_encode( ..., JSON_UNESCAPED_SLASHES ).
P.S. sometimes fields want to be rawurlencode()'d, I have a note for this for Discord webhooks.

by Daneel_Trevize(in Reddit)

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.