PHP Classes
elePHPant
Icontem

Simple API REST Class PHP: Process REST API server requests

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-10-09 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 232 This week: 11All time: 7,739 This week: 57Up
Version License PHP version Categories
simple-api-rest-clas 1.0Artistic License5PHP 5, Web services
Description Author

This package can process REST API server requests.

It can process HTTP GET, POST, PUT and DELETE requests.

The package can extract parameters so server API script can handle the API requests.

  Performance   Level  
Name: Juan Chaves <contact>
Classes: 9 packages by
Country: Spain Spain
Age: 54
All time rank: 156233 in Spain Spain
Week rank: 35 Up3 in Spain Spain Up

Details
# simple-api-rest-class-php
This class displays a Simple Api Rest query in json format.
Services GET, POST, PUT and DELETE.


$this->session_ok:
It is used to confirm that the user is accredited

$query->query:
Separate comma array to create, access, modify, or delete an element
note: in the put service only one field can be updated at a time

$query->update:
Array separated by comma, update the fields with the format (title: value, title: value) for service only put

$query->allows_services:
Type of service I allow in the query

To use the example, first download all the files, import simple_api_rest.sql and put the connection data to the database in connect.php.php. Then log in to login.html.

<pre>
<h2>Service post</h2>
//example_post.php?q=Iphone,Asus
if($_SESSION['loggedin']) {
	include('./simple_api_rest_class.php');
	//Example
	$query = new SimpleApiRestClass();
	$query->session_ok = $_SESSION['loggedin'];
	$query->query = $_REQUEST['q'];
	$query->allows_services = 'post';
	$post_query = $query->ReturnLogin();
	include('./server.php');
} else {

	echo 'You must be logged in to access this site'; 
	
}

<h2>Service put</h2>
//example_put.php?q=Iphone&u=name:Tablet,value:103
if($_SESSION['loggedin']) {
	include('./simple_api_rest_class.php');
	include('./login.php');
	//Example
	$query = new SimpleApiRestClass();
	$query->session_ok = $_SESSION['loggedin'];
	$query->query = $_REQUEST['q'];
	$query->update = $_REQUEST['u'];
	$query->allows_services = 'put';
	$post_query = $query->ReturnLogin();
	include('./server.php');
} else {

	echo 'You must be logged in to access this site'; 
	
}

<h2>Service get</h2>
//example_get.php?q=Iphone,Asus
if($_SESSION['loggedin']) {
	include('./simple_api_rest_class.php');
	//Example
	$query = new SimpleApiRestClass();
	$query->session_ok = $_SESSION['loggedin'];
	$query->query = $_REQUEST['q'];
	$query->allows_services = 'get';
	$post_query = $query->ReturnLogin();
	include('./server.php');
} else {

	echo 'You must be logged in to access this site'; 
	
}

<h2>Service delete</h2>
//example_delete.php?q=Iphone,Asus
if($_SESSION['loggedin']) {
	include('./simple_api_rest_class.php');
	//Example
	$query = new SimpleApiRestClass();
	$query->session_ok = $_SESSION['loggedin'];
	$query->query = $_REQUEST['q'];
	$query->allows_services = 'delete';
	$post_query = $query->ReturnLogin();
	include('./server.php');
} else {

	echo 'You must be logged in to access this site'; 
	
}

</pre>
  Files folder image Files  
File Role Description
Accessible without login Plain text file check_login.php Aux. Auxiliary script
Accessible without login Plain text file connect.php Aux. Auxiliary script
Accessible without login Plain text file example_delete.php Example Example script
Accessible without login Plain text file example_get.php Example Example script
Accessible without login Plain text file example_post.php Example Example script
Accessible without login Plain text file example_put.php Example Example script
Accessible without login HTML file login.html Doc. Documentation
Accessible without login HTML file README.md Doc. Documentation
Accessible without login Plain text file server.php Example Example script
Accessible without login Plain text file simple_api_rest.sql Data Auxiliary data
Plain text file simple_api_rest_class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:232
This week:11
All time:7,739
This week:57Up