-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
87 lines (74 loc) · 2.32 KB
/
index.php
File metadata and controls
87 lines (74 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
// +------------------------------------------------------------------------+
// | @author : Michael Arawole (Logad Networks)
// | @author_url : https://www.logad.net
// | @author_email : logadscripts@gmail.com
// | @date : 20 Jan, 2023 12:38 AM
// +------------------------------------------------------------------------+
// +----------------------------+
// | Test
// +----------------------------+
require 'vendor/autoload.php';
use LogadApp\Http\Http;
use LogadApp\Http\Response;
use LogadApp\Http\Request;
$request = (new Request($_GET, $_POST, $_FILES, file_get_contents('php://input'), getallheaders()));
$response = new Response;
// print_r($request->getBody());
$response->json([
'error' => false,
'method' => $request->getMethod(),
'body' => $request->getBody(),
'headers' => $request->getHeaders(),
'query' => $request->getQueryParams(),
'content-type' => $request->getContentType()
])
->send();
if (!empty($request->getQueryParams())) {
$response
->json([
'error' => false,
'message' => 'It\'s all good',
'data' => $request->getQueryParams()
])
// Direct status code can be used. But I recommend this
->withStatus(Response::HTTP_OK)
->send();
} else {
$response
->json([
'error' => true,
'message' => 'Please add query parameter(s)',
'data' => []
])
// Direct status code can be used. But I recommend this
->withStatus(Response::HTTP_BAD_REQUEST)
->send();
try {
$postResponse = Http::post('http://localhost')
->setBody(json_encode([
'name' => 'Michael'
]))
->send();
echo 'Body', PHP_EOL;
print_r($postResponse->getResponseBody());
echo PHP_EOL;
echo 'Headers', PHP_EOL;
print_r($postResponse->getResponseHeaders());
echo PHP_EOL;
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
Http::build([
'url' => 'https://www.logad.net',
])
->setBody('Hello World')
->setHeaders([
'Content-Type' => 'text/plain'
])
->send();
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
}