Skip to content

Building a RESTful Web Service :: Learn how to create a RESTful web service with Yii2

Notifications You must be signed in to change notification settings

OpenSooq/WebService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebService extension

curl extension for Yii2:

  • POST
  • GET
  • HEAD
  • PUT
  • DELETE

Requirements

  • PHP 5.4+
  • Curl and php-curl installed

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist opensooq/webservice

or add

"opensooq/web-service": "*"

Usage

  • GET
//Create GET request
$url = 'https://apilayer.net/api/convert';
$getParams = ['from'=>'USD','to'=>'EUR','amount'=>1];
$options   = [CURLOPT_TIMEOUT=>40];
$headers   = ['Content-Type'=>'application/json'];

// GET
$response   = HttpClient::get($url, $getParams, $headers,$options);
OUTPUT:
Array
(
    [info] => Array
        (
            [code] => 200
            [Content-Type] => application/json; Charset=UTF-8
            [curl-error] =>
            [curl-header] => GET /api/convert?from=USD&to=EUR&amount=1 HTTP/1.1
                            Host: apilayer.net
                            User-Agent: OpenSooqClient 1.0
                            Accept: */*
                            Content-Type: application/json
                            Content-Length: 2


        )

    [response] => stdClass Object
        (
            [success] =>
            [error] => stdClass Object
                (
                    [code] => 101
                    [type] => missing_access_key
                    [info] => You have not supplied an API Access Key. [Required format: access_key=YOUR_ACCESS_KEY]
                )

        )

)
  • POST
// Make sure you fill
$response = HttpClient::post($url,$postParams,$getParams, $headers, $options)
  • General Request
//Init webservice
$verb = 'PUT';
$response = HttpClient::request($verb,$url,$getParams,null, $headers, $options)

About

Building a RESTful Web Service :: Learn how to create a RESTful web service with Yii2

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages