IClient.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP\Http\Client;
  25. /**
  26. * Interface IClient
  27. *
  28. * @package OCP\Http
  29. * @since 8.1.0
  30. */
  31. interface IClient {
  32. /**
  33. * Sends a GET request
  34. * @param string $uri
  35. * @param array $options Array such as
  36. * 'query' => [
  37. * 'field' => 'abc',
  38. * 'other_field' => '123',
  39. * 'file_name' => fopen('/path/to/file', 'r'),
  40. * ],
  41. * 'headers' => [
  42. * 'foo' => 'bar',
  43. * ],
  44. * 'cookies' => ['
  45. * 'foo' => 'bar',
  46. * ],
  47. * 'allow_redirects' => [
  48. * 'max' => 10, // allow at most 10 redirects.
  49. * 'strict' => true, // use "strict" RFC compliant redirects.
  50. * 'referer' => true, // add a Referer header
  51. * 'protocols' => ['https'] // only allow https URLs
  52. * ],
  53. * 'save_to' => '/path/to/file', // save to a file or a stream
  54. * 'verify' => true, // bool or string to CA file
  55. * 'debug' => true,
  56. * @return IResponse
  57. * @throws \Exception If the request could not get completed
  58. * @since 8.1.0
  59. */
  60. public function get(string $uri, array $options = []): IResponse;
  61. /**
  62. * Sends a HEAD request
  63. * @param string $uri
  64. * @param array $options Array such as
  65. * 'headers' => [
  66. * 'foo' => 'bar',
  67. * ],
  68. * 'cookies' => ['
  69. * 'foo' => 'bar',
  70. * ],
  71. * 'allow_redirects' => [
  72. * 'max' => 10, // allow at most 10 redirects.
  73. * 'strict' => true, // use "strict" RFC compliant redirects.
  74. * 'referer' => true, // add a Referer header
  75. * 'protocols' => ['https'] // only allow https URLs
  76. * ],
  77. * 'save_to' => '/path/to/file', // save to a file or a stream
  78. * 'verify' => true, // bool or string to CA file
  79. * 'debug' => true,
  80. * @return IResponse
  81. * @throws \Exception If the request could not get completed
  82. * @since 8.1.0
  83. */
  84. public function head(string $uri, array $options = []): IResponse;
  85. /**
  86. * Sends a POST request
  87. * @param string $uri
  88. * @param array $options Array such as
  89. * 'body' => [
  90. * 'field' => 'abc',
  91. * 'other_field' => '123',
  92. * 'file_name' => fopen('/path/to/file', 'r'),
  93. * ],
  94. * 'headers' => [
  95. * 'foo' => 'bar',
  96. * ],
  97. * 'cookies' => ['
  98. * 'foo' => 'bar',
  99. * ],
  100. * 'allow_redirects' => [
  101. * 'max' => 10, // allow at most 10 redirects.
  102. * 'strict' => true, // use "strict" RFC compliant redirects.
  103. * 'referer' => true, // add a Referer header
  104. * 'protocols' => ['https'] // only allow https URLs
  105. * ],
  106. * 'save_to' => '/path/to/file', // save to a file or a stream
  107. * 'verify' => true, // bool or string to CA file
  108. * 'debug' => true,
  109. * @return IResponse
  110. * @throws \Exception If the request could not get completed
  111. * @since 8.1.0
  112. */
  113. public function post(string $uri, array $options = []): IResponse;
  114. /**
  115. * Sends a PUT request
  116. * @param string $uri
  117. * @param array $options Array such as
  118. * 'body' => [
  119. * 'field' => 'abc',
  120. * 'other_field' => '123',
  121. * 'file_name' => fopen('/path/to/file', 'r'),
  122. * ],
  123. * 'headers' => [
  124. * 'foo' => 'bar',
  125. * ],
  126. * 'cookies' => ['
  127. * 'foo' => 'bar',
  128. * ],
  129. * 'allow_redirects' => [
  130. * 'max' => 10, // allow at most 10 redirects.
  131. * 'strict' => true, // use "strict" RFC compliant redirects.
  132. * 'referer' => true, // add a Referer header
  133. * 'protocols' => ['https'] // only allow https URLs
  134. * ],
  135. * 'save_to' => '/path/to/file', // save to a file or a stream
  136. * 'verify' => true, // bool or string to CA file
  137. * 'debug' => true,
  138. * @return IResponse
  139. * @throws \Exception If the request could not get completed
  140. * @since 8.1.0
  141. */
  142. public function put(string $uri, array $options = []): IResponse;
  143. /**
  144. * Sends a DELETE request
  145. * @param string $uri
  146. * @param array $options Array such as
  147. * 'body' => [
  148. * 'field' => 'abc',
  149. * 'other_field' => '123',
  150. * 'file_name' => fopen('/path/to/file', 'r'),
  151. * ],
  152. * 'headers' => [
  153. * 'foo' => 'bar',
  154. * ],
  155. * 'cookies' => ['
  156. * 'foo' => 'bar',
  157. * ],
  158. * 'allow_redirects' => [
  159. * 'max' => 10, // allow at most 10 redirects.
  160. * 'strict' => true, // use "strict" RFC compliant redirects.
  161. * 'referer' => true, // add a Referer header
  162. * 'protocols' => ['https'] // only allow https URLs
  163. * ],
  164. * 'save_to' => '/path/to/file', // save to a file or a stream
  165. * 'verify' => true, // bool or string to CA file
  166. * 'debug' => true,
  167. * @return IResponse
  168. * @throws \Exception If the request could not get completed
  169. * @since 8.1.0
  170. */
  171. public function delete(string $uri, array $options = []): IResponse;
  172. /**
  173. * Sends a options request
  174. * @param string $uri
  175. * @param array $options Array such as
  176. * 'body' => [
  177. * 'field' => 'abc',
  178. * 'other_field' => '123',
  179. * 'file_name' => fopen('/path/to/file', 'r'),
  180. * ],
  181. * 'headers' => [
  182. * 'foo' => 'bar',
  183. * ],
  184. * 'cookies' => ['
  185. * 'foo' => 'bar',
  186. * ],
  187. * 'allow_redirects' => [
  188. * 'max' => 10, // allow at most 10 redirects.
  189. * 'strict' => true, // use "strict" RFC compliant redirects.
  190. * 'referer' => true, // add a Referer header
  191. * 'protocols' => ['https'] // only allow https URLs
  192. * ],
  193. * 'save_to' => '/path/to/file', // save to a file or a stream
  194. * 'verify' => true, // bool or string to CA file
  195. * 'debug' => true,
  196. * @return IResponse
  197. * @throws \Exception If the request could not get completed
  198. * @since 8.1.0
  199. */
  200. public function options(string $uri, array $options = []): IResponse;
  201. }