Giter Site home page Giter Site logo

curl-service-package's Introduction

curl service package

A composer package that provides simple helpers for calling both REST and SOAP APIs in PHP. The package utilizes PHP cURL in an object orientated approach.

To install:

composer require clvr1/curl-service

When creating an instance of curlService there are 2 paramaters.
1.) The API endpoint (URL) - required.

2.) A auth array that contains the API username and password if necessary - optional.

e.g. Creating an instance of curlService with auth.

$testAPI = new curlService("https://testapi.com/api", Array(
    "username" => "testUser",
    "password" => "testPwd"
));

Add Headers

To add headers to a request you can call the addHeaders() method in curlService.

$testAPI -> addHeaders(Array(
	"Content-type: application/xml",
	"Authorization: test",
));

Add URL parameters

To add URL params to an endpoint, you can call the addURLParams() method in curlService. This method expects an array of key value pairs that are added as URL parameters at the end of the endpoint.

$testAPI -> addURLParams(Array(
    "key1" => "value1",
    "key2" => "value2",
));

This example will modify the endpoint like so: "https://testapi.com/api?key1=value1&key2=value2".

GET REQ

$testAPI -> get();

POST REQ

$testAPI -> post(Array(
    "key1" => "value1",
    "key2" => "value2",
));

PUT REQ

$testAPI -> put(Array(
    "key1" => "value1",
    "key2" => "value2",
));

SOAP REQ

To MAKE A SOAP POST request you can call the soap() method in curlService. This method expects an array of SOAP parameters which is then formatted into a xml string (formatSoapXML() in cURLServiceBase).

e.g.

$testAPI -> soap(
  "paramKey1" => Array(
     "key" => "value"			
  ),
);

This example will format a xml post string like so:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<m: paramKey1>
			<m: key>value</m: key>
		</m: paramKey1>
	</soap:Body>
</soap:Envelope>

curl-service-package's People

Contributors

charlielaver avatar

Stargazers

 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.