Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Created December 5, 2016 16:00
Show Gist options
  • Save igoralves1/b0decd0ddff89e64498553ca3b69a870 to your computer and use it in GitHub Desktop.
Save igoralves1/b0decd0ddff89e64498553ca3b69a870 to your computer and use it in GitHub Desktop.
API/v1/get/get_list.php
//This API was ispired by White House Web API Standards => https://github.com/WhiteHouse/api-standards
//This method should provide more flexibility to the front-end team.
//We can create queries directly in the URL and grab the result in JSON to be used to render DOM objects or arr to debug prupose.
<?php
header('Content-Type:application/json');
include_once '../../../class/db.php';
$verb=$_SERVER['REQUEST_METHOD'];
if($verb=="GET"){
if(isset($_GET["tbl"])){//Use default select * from $_GET["tbl"]
header("HTTP/1.1 200 ok");
$arrURI= explode(".", $_GET['tbl']);
$tblName=$arrURI[0];
$displayType=$arrURI[1];
//die(print_r($displayType));
if(isset($_GET["fields"]) && isset($_GET["complement"])){
if(preg_match("/delete|insert|update/i", $_GET["complement"])||preg_match("/delete|insert|update/i", $_GET["fields"])){
die("Delete or Update ou Insert not allowed. Use appropriate API tool.");
}
else{
$fields = $_GET["fields"];
$complement = $_GET["complement"];
echo db::get_list($tblName, $displayType, $fields, $complement);
}
}
else{
//die("Missing filds or complemet in your query.");
echo db::get_list($tblName, $displayType);
}
}
else{//use select statement
die("Missing tbl variable in your query. Use ... .php?tbl=tblname.json or ... .php?tbl=tblname.arr");
}
}
else{
die("This is a GET end point");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment