|
| 1 | + |
| 2 | +<p><img src="https://eu.ui-avatars.com/api/?name=Najm+Njeim?size=100" width="100"/></p> |
| 3 | + |
| 4 | +## Nnjeim Guzzle Wrapper |
| 5 | + |
| 6 | +A Laravel wrapper for the Guzzle client http library. It provides a fluent syntax to make http requests. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +You can install the package via composer: |
| 11 | +``` |
| 12 | +composer require nnjeim/fetch |
| 13 | +``` |
| 14 | + |
| 15 | +## Configuration |
| 16 | +``` |
| 17 | +php artisan vendor:publish --provider="Nnjeim\Fetch\FetchServiceProvider" |
| 18 | +``` |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +##### Fetch Facade |
| 23 | + |
| 24 | +``` |
| 25 | +use Nnjeim\Fetch\Fetch; |
| 26 | +
|
| 27 | +$countries = Fetch::setBaseUri('https://someapi.com')->get('countries'); |
| 28 | +``` |
| 29 | +##### FetchHelper Instantiation |
| 30 | +``` |
| 31 | +use Nnjeim\Fetch\FetchHelper; |
| 32 | +
|
| 33 | +private $fetch; |
| 34 | +
|
| 35 | +public function __construct(FetchHelper $fetch) { |
| 36 | +
|
| 37 | + $this->fetch = $fetch; |
| 38 | +} |
| 39 | +
|
| 40 | +. |
| 41 | +. |
| 42 | +. |
| 43 | +return $this->fetch |
| 44 | + ->setBaseUri('https://someapi.com') |
| 45 | + ->get('countries'); |
| 46 | +``` |
| 47 | + |
| 48 | +## Methods |
| 49 | + |
| 50 | +##### Set the headers |
| 51 | +``` |
| 52 | +Set the http headers |
| 53 | +
|
| 54 | +@return $this setHeaders(array $headers) |
| 55 | +``` |
| 56 | + |
| 57 | +##### Set the base uri |
| 58 | +``` |
| 59 | +Sets the base uri for the composition of the http request url. |
| 60 | +
|
| 61 | +@return $this setBaseUri(string 'http://someapi.com/') |
| 62 | +``` |
| 63 | + |
| 64 | +##### Set the request url |
| 65 | +``` |
| 66 | +Sets the http request url. |
| 67 | +
|
| 68 | +@return $this setUrl(string $url) |
| 69 | +``` |
| 70 | + |
| 71 | +##### Set the request method |
| 72 | +``` |
| 73 | +Sets the http request method. |
| 74 | +
|
| 75 | +@return $this setMethod(string $method) |
| 76 | +``` |
| 77 | + |
| 78 | +##### Set the request body format |
| 79 | +``` |
| 80 | +Sets the request body format. The required format are 'query' | 'form_params' | 'multipart'. |
| 81 | +
|
| 82 | +@return $this setBodyFormat(string $format) |
| 83 | +``` |
| 84 | + |
| 85 | +##### Async request |
| 86 | +``` |
| 87 | +Sets the type of the request to async. |
| 88 | +
|
| 89 | +@return $this setAsync() |
| 90 | +``` |
| 91 | + |
| 92 | +##### Get request |
| 93 | +``` |
| 94 | +Sets the body format to query. |
| 95 | +
|
| 96 | +@return array get(?string $url = null, ?array $data = null) |
| 97 | +``` |
| 98 | + |
| 99 | +##### Post request |
| 100 | +``` |
| 101 | +Sets the body format to form-params. |
| 102 | +
|
| 103 | +@return array post(?string $url = null, ?array $data = null) |
| 104 | +``` |
| 105 | + |
| 106 | +##### Put request |
| 107 | +``` |
| 108 | +Sets the body format to form-params. |
| 109 | +
|
| 110 | +@return array put(?string $url = null, ?array $data = null) |
| 111 | +``` |
| 112 | + |
| 113 | +##### Delete request |
| 114 | +``` |
| 115 | +Sets the body format to query. |
| 116 | +
|
| 117 | +@return array delete(?string $url = null, ?array $data = null) |
| 118 | +``` |
| 119 | + |
| 120 | +##### Upload request |
| 121 | +``` |
| 122 | +Sets the body format to multipart. |
| 123 | +
|
| 124 | +@return array upload(?string $url = null, ?array $data = null) |
| 125 | +``` |
| 126 | + |
| 127 | +## Response |
| 128 | + |
| 129 | +``` |
| 130 | +@return array |
| 131 | +
|
| 132 | + [ |
| 133 | + 'response' => ..., |
| 134 | + 'status' => ..., |
| 135 | + ]; |
| 136 | +``` |
| 137 | +## Testing |
| 138 | + |
| 139 | +``` bash |
| 140 | +composer test |
| 141 | +``` |
| 142 | + |
| 143 | +## Changelog |
| 144 | + |
| 145 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
0 commit comments