-
Notifications
You must be signed in to change notification settings - Fork 41
/
api_template.php
40 lines (32 loc) · 1.14 KB
/
api_template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
//include the API Builder mini lib
require_once("api_builder_includes/class.API.inc.php");
//set page to output JSON
header("Content-Type: application/json; charset=utf-8");
//If API parameters were included in the http request via $_GET...
if(isset($_GET) && !empty($_GET)){
//specify the columns that will be output by the api as a comma-delimited list
$columns = "column_name,
column_name,
column_name,
column_name,
column_name,
etc...";
//setup the API
$api = new API("your_host",
"your_database_name",
"your_table_name",
"your_database_username",
"your_database_password");
$api->setup($columns);
$api->set_default_order("column_name");
$api->set_searchable("column_name, column_name, etc...");
$api->set_default_search_order("column_name");
$api->set_pretty_print(true);
//sanitize the contents of $_GET to insure that
//malicious strings cannot disrupt your database
$get_array = Database::clean($_GET);
//output the results of the http request
echo $api->get_json_from_assoc($get_array);
}
?>