1. Go to this page and download the library: Download siu-toba/rest 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/ */
siu-toba / rest example snippets
php
//Equivale a GET /rest/{id}: retorna un recurso puntual
function get($id) ...
//Equivale a DELETE /rest/{id}: elimina un recurso puntual
function delete($id) ...
//Equivale a PUT /rest/{id}: modifica parte de los atributos del recuso
function put($id) ...
php
class recurso_personas
{
function get($id_persona)
{
$modelo = new modelo_persona($id_persona);
$fila = $modelo->get_datos();
rest::response()->get($fila);
}
function delete($id_persona)
{
$modelo = new modelo_persona($id_persona);
$ok = $modelo->delete();
$errores = array();
if (!$ok) {
rest::response()->not_found();
} else {
rest::response()->delete($errores);
}
}
function put($id_persona)
{
$datos = rest::request()->get_body_json();
$modelo = new modelo_persona($id_persona);
$ok = $modelo->update($datos);
if (!$ok) {
rest::response()->not_found();
} else {
rest::response()->put();
}
}
}
php
// Equivale a GET /rest: retorna el recurso como un conjunto
function get_list() ...
// Equivale a POST /rest: da de alta un nuevo recurso
function post_list($id) ...
php
class recurso_personas
{
function post_list()
{
$datos = rest::request()->get_body_json();
$nuevo = modelo_persona::insert($datos);
$fila = array('id' => $nuevo);
rest::response()->post($fila);
}
function get_list()
{
$personas = modelo_persona::get_personas($where);
rest::response()->get($personas);
}
php
class recurso_documento
{
function get_list()
{
$pdf = documentos::get_pdf();
$vista_pdf = new \SIUToba\rest\http\vista_raw(rest::response());
$vista_pdf->set_content_type("application/pdf");
rest::app()->set_vista($vista_pdf);
rest::response()->set_data($pdf);
rest::response()->set_status(200);
rest::response()->add_headers(array(
"Content-Disposition" => "attachment; filename=Mi_documento.pdf"
));
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.