Restful Library ({{ZN >= 4.3.5}})



( ZN >= 4.3.5 )

REST ( Representational state transfe r ) is a distributed system that uses Web protocols and technologies. Systems that provide REST principles are qualified as RESTful . The representation in the name Representative Case Transfer refers to the representation of the data and can be thought of as transferring the state of the case.

It was developed in 2000 by Roy Fielding, one of the authors of the HTTP specification, as part of his doctoral thesis.

It has been developed as a simpler alternative to specification of SOAP and WSDL based Web services. RESTful systems communicate with HTTP verbs ( GET , POST , PUT, DELETE, etc.) , which are often used by Web browsers to transfer pages via the HTTP protocol .

The format of the exported data can be HTML, JSON, XML, or a different type. REST does not impose any restrictions on this. The type of data being transferred and features fine for client and HTTP protocol by servers located in the content-type (content type) and the like are defined by metadata.

 

# Methods


Object get ( String $ url = NULL )
Object post ( String $ url = NULL , Mixed $ data = NULL )
Mixed put ( String $ url = NULL , Mixed  $ data = NULL )
Mixed delete ( String $ url = NULL , Mixed $ data = NULL )
void return ( Callable $ callback )
this url ( String $ url )
this data ( Mixed $ data )
this contentType ( String $ type = 'json' , String $ charset = 'utf-8' )
this httpStatus ( Int $ code = NULL )

 

# Get ( ZN >= 4.3.5 )


Used to list data. Generally, the output of the API provider is taken. This output is returned as data from the Object type.

Parameters

String $ url The URL to connect to.
return Object

Use of

$response = Restful::get('https://api.openweathermap.org/data/2.5/forecast/city?q=istanbul&APPID=25e585073d9232f10fa66afa76d62fda');

output($response);

 

# Post ( ZN >= 4.3.5 )


It is used for posting to API services. It is usually used to send data to the codes in the API provider. Thus, you can get the output you want according to the amount you send. On-the-go is just used to send data.

Parameters

String $ url The URL to connect to.
Mixed $ data The sender is given. Instead of this parameterdata() may also be utilized.
return Object

Use of

Restful::data
([
    'title'        => $title, 
    'access_token' => $accessToken,
    'receivers'    => $receivers,
    'content'      => $message
])
->post('https://api.bulutfon.com/messages');

 

# Put  ( ZN >= 4.3.5 )


It is usually used to update the data in the API provider. Its use with Post () is the same. It is just different in meaning.

Parameters

String $ url The URL to connect to.
Mixed $ data The sender is given. Instead of this parameterdata() may also be utilized.
return Object

Use of

Restful::data
([
    'id'     => $id,
    'update' => ['name' => $name, 'ip' => User::ip()]
])
->put('https://example.com/apis/update');

 

# Delete  ( ZN> = 4.3.5 )

It is usually used to delete the data from the API provider. Its use with Post () is the same. It is just different in meaning.

Parameters

String $ url The URL to connect to.
Mixed $ data The sender is given. Instead of this parameterdata() may also be utilized.
return Object

Use of

Restful::data
([
    'id'     => $id
])
->delete('https://example.com/apis/delete');

 

# R e turn ( ZN >= 4.3.5 )

Used to create a data provider. It is used to generate json or xml output according to the post, get or uri data received when remote request is made to your machine.

Parameters

callable $ CallBack Commands to run.
return void

Use of

Below is an example usage.

Response / Response

Response Address: domain.com/apis/api
<?php namespace Project\Controllers;

use Restful, DB, Method;

class Api extends Controller
{
    public function ex()
    {
        Restful::contentType('json')->return(function()
        {
            echo DB::where('id', Method::post('id'))
                   ->select('username', 'phone')
                   ->get('users')->resultJson();
        });
    }
}

Request / Request 

Request Address: mysite.com/example/request
<?php namespace Project\Controllers;

use Restful;

class Example extends Controller
{
    public function request()
    {
        $rest = Restful::post('domain.com/apis/api', ['id' => 4]);

        output($rest);
    }
}
0 => object
(
        username => string 'example' (length = 9 )
        phone => string ' (length = 2 )