PHP code example of ant-framework / http

1. Go to this page and download the library: Download ant-framework/http library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ant-framework / http example snippets




$request = new \Ant\Http\Request('GET','http://www.example.com');

echo $request;

//output ..
/*
GET / HTTP/1.1
Host: www.example.com


*/



$response = new \Ant\Http\Response();

// 选择装饰器,设置内容,装饰response
$response = $response->selectRenderer('json')
    ->setPackage(['foo' => 'bar'])
    ->decorate($response);

echo $response;
//output ..
/*
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8

{"foo":"bar"}
*/