https://github.com/abgeo/webii-hw01-request-response
https://github.com/abgeo/webii-hw01-request-response
hw request response web2
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/abgeo/webii-hw01-request-response
- Owner: ABGEO
- License: mit
- Created: 2019-02-26T10:33:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-04T08:03:37.000Z (over 7 years ago)
- Last Synced: 2025-04-10T00:37:43.228Z (about 1 year ago)
- Topics: hw, request, response, web2
- Language: PHP
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WEBII-HW01-Request-Response
## Including
Include Autoloader
```php
require_once __DIR__ . '/Services/autoloader.php';
```
## Class Request
Import class
```php
use web2hw\Request;
```
Crete class new object
```php
$request = new Request();
```
### Class Methods
#### getHeaders()
Get request HTTP Headers
Get all headers
```php
$allHeaders = $request->getHeaders();
```
Get single header (Ex.: Host)
```php
$singleHeader = $request->getHeaders('Host');
```
Get more then one header
```php
$manyHeaders = $request->getHeaders(['Accept', 'Accept-Encoding']);
```
##### Allowed headers
[MDN - HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers "MDN - HTTP headers")
#### getMethod()
Get request HTTP method
#### hasHeader($key)
Check if request has header
#### getPath()
Get request path
#### getScheme()
Get request scheme(http or https)
#### getQueryParams()
Get request query parameters
#### getQuery($key)
Get request query parameter by key
#### getData()
Get request data by method
## Class Response
Import class
```php
use web2hw\Response;
```
Prepare data for transmission (Ex.: Array)
```php
$arr = [
'test' => 'vTest',
'test2' => [
'test2.1' => '2.1',
'test2.2' => [
'test2.2.1' => '2.2.1'
]
]
];
```
Crete class new object
Class takes 3 arguments:
- Content (**Required**; Mixed) - The data for returning
- Status Code (**Optional**; 200 by default; Integer) - The HTTP Status Code
- HTTP Headers (**Optional**; empty by default; Key Value Array) - The HTTP Headers
```php
$response = new Response(json_encode($arr), 200, ['Content-Type' => 'application/json']);
```
And send it
```php
echo $response->sendResponse();
```
**2019 © Temuri Takalandze**