Fork me on GitHub

Application - Request

#Request

#Overview

CafeLatte(CL) receives an HTTP request via ROUTE from web browser such as 'Chrome','Safari','Windows Explorer', 'FireFox' etc.

Requests allow you to send HEAD, GET, POST, PUT, DELETE, and PATCH HTTP requests. You can add headers, form data, multipart files, and parameters with simple arrays, and access the response data in the same way. Requests uses cURL and fsockopen, depending on what your system has available, but abstracts all the nasty stuff out of your way, providing a consistent API.

#Support Request

#How To Use

#GET Parameter

CafeLatte(CL) receives an HTTP request with the GET method's parameters via the ROUTE

GET Request Info


http://yourdomain.com/sms/dosend/?number=01012102102&message=bodymessage

PHP code


$key1 = $this->request->get('number');
$key2 = $this->request->get('bodymessage');

Response Data


01012102102
bodymessage

#POST Parameter

CafeLatte(CL) receives an HTTP request with the POST method's parameters via the ROUTE.

POST Request Info(HTML Code)


<form action="http://youtdomain.com/update/userid" method='post'>
    <input type="text" name="name"  value='cafelatte'>
    <input type="text" name="email"  value='cafelatte@cafelatte.co.kr'>
    <input type="text" name="number"  value='10000'>
    <input type="submit" name="submit">
</form>

PHP code


$name = $this->request->post('name');
$email = $this->request->post('email');
$number = $this->request->post('number');

Response Data


01012102102
cafelatte@cafelatte.co.kr
10000

#HEADER Parameter

CafeLatte(CL) receives an HTTP request with the POST method's parameters via the ROUTE.

HEADER Request Info


Content-Type:application/x-www-form-urlencoded
key1:value1
name:hello

PHP code


$key1 = $this->request->header('key1');
$name = $this->request->header('name');

Response Data


value1
hello

#COOKIE Parameter

CafeLatte(CL) receives an HTTP request with the POST method's parameters via the ROUTE.

COOKIE Request Info


key1=value; key2=value; path=/; domain=.youtdomain.com;

PHP code


$key1 = $this->request->cookie('key1');
$key2 = $this->request->cookie('key2');

Response Data


value1
value2

#SESSION Parameter

PHP code


$key1 = $this->request->session('key1');
$key2 = $this->request->session('key2');

#SERVER Parameter

PHP code



$key1 = $this->request->server('key1');
$key2 = $this->request->server('key2');

#FILE Parameter

CafeLatte(CL) receives an HTTP request with the POST method's parameters via the ROUTE.

File Attach Info


<form action="http://youtdomain.com/upload/profile" method='post' enctype="multipart/form-data">
    <input type="file" name="attachFile"  value='testimg.jpg'>
    <input type="submit" name="upload">
</form>

PHP code


$fileInfo = $this->request->file('attachFile');

print_r($fileInfo);

Response Data


Array
(
    [name] => 20171013_163612.jpg
    [type] => image/jpg
    [tmp_name] => /tmp/phpQp9ByF
    [error] => 0
    [size] => 1610
)

#Full Example

index.php


<?php

require_once("/home/projects/my_project/autoload.php");

class TestRoute extends \CafeLatte\Core\BaseRoute implements \CafeLatte\Interfaces\RouterInterface
{
    public function routing()
    {

        $this->router->get("", function () {
            $number = $this->request->get('number');
            $message = $this->request->header('message');
            $phpSessionId = $this->request->cookie('PHPSESSID');
            $sessionKey = $this->request->session('sessionKey');

            echo "_GET['number'] : " . $number . "\n";
            echo "_HEADER['message'] : " . $message . "\n";
            echo "_COOKIE['PHPSESSID'] : " . $phpSessionId . "\n";
            echo "_SESSION['sessionKey'] : " . $sessionKey . "\n";
        });

        $this->router->post("", function () {
            $number = $this->request->post('number');
            $message = $this->request->header('message');
            $phpSessionId = $this->request->cookie('PHPSESSID');
            $sessionKey = $this->request->session('sessionKey');
            $attacheFile = $this->request->file('attacheFile');

            echo "_POST['number'] : " . $number . "\n";
            echo "_HEADER['message'] : " . $message . "\n";
            echo "_COOKIE['PHPSESSID'] : " . $phpSessionId . "\n";
            echo "_SESSION['sessionKey'] : " . $sessionKey . "\n";
            echo "_FILE['attacheFile'] : " . print_r($attacheFile);

        });

        $this->router->put("", function () {
            $number = $this->request->put('number');
            $message = $this->request->header('message');
            $phpSessionId = $this->request->cookie('PHPSESSID');
            $sessionKey = $this->request->session('sessionKey');
            $attacheFile = $this->request->file('attacheFile');

            echo "_GET['number'] : " . $number . "\n";
            echo "_HEADER['message'] : " . $message . "\n";
            echo "_COOKIE['PHPSESSID'] : " . $phpSessionId . "\n";
            echo "_SESSION['sessionKey'] : " . $sessionKey . "\n";
            echo "_FILE['attacheFile'] : " . print_r($attacheFile);
        });

        $this->router->delete("", function () {
            $number = $this->request->delete('number');
            $message = $this->request->header('message');
            $phpSessionId = $this->request->cookie('PHPSESSID');
            $sessionKey = $this->request->session('sessionKey');
            $attacheFile = $this->request->file('attacheFile');

            echo "_GET['number'] : " . $number . "\n";
            echo "_HEADER['message'] : " . $message . "\n";
            echo "_COOKIE['PHPSESSID'] : " . $phpSessionId . "\n";
            echo "_SESSION['sessionKey'] : " . $sessionKey . "\n";
            echo "_FILE['attacheFile'] : " . print_r($attacheFile);
        });


        //DO NOT REMOVE
        $this->router->run();
    }

}

$framework = new TestRoute("/home/projects/my_project/cafelatte.json");
$framework->execute();

#Tutorial

To get more information, move to tutorial page, Click `Here`