https://github.com/opensooq/webservice
Building a RESTful Web Service :: Learn how to create a RESTful web service with Yii2
https://github.com/opensooq/webservice
curl webservice yii2
Last synced: 3 months ago
JSON representation
Building a RESTful Web Service :: Learn how to create a RESTful web service with Yii2
- Host: GitHub
- URL: https://github.com/opensooq/webservice
- Owner: OpenSooq
- Created: 2016-10-24T12:44:29.000Z (over 8 years ago)
- Default Branch: devlop
- Last Pushed: 2017-06-16T18:32:16.000Z (almost 8 years ago)
- Last Synced: 2025-01-10T23:42:29.752Z (4 months ago)
- Topics: curl, webservice, yii2
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
WebService extension
====================curl extension for Yii2:
- POST
- GET
- HEAD
- PUT
- DELETERequirements
------------
- PHP 5.4+
- Curl and php-curl installedInstallation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```bash
php composer.phar require --prefer-dist opensooq/webservice
```or add
```php
"opensooq/web-service": "*"
```Usage
-----
- GET```php
//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);
```
```php
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```php
// Make sure you fill
$response = HttpClient::post($url,$postParams,$getParams, $headers, $options)
```- General Request
```php
//Init webservice
$verb = 'PUT';
$response = HttpClient::request($verb,$url,$getParams,null, $headers, $options)
```