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 (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-12-06 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 371 All time: 6,649 This week: 309Up
Version License PHP version Categories
simple-api-rest-clas 1.1Artistic 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: 11 packages by
Country: Spain Spain
Innovation award
Innovation award
Nominee: 1x

 

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

$this->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

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

$this->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 CODE_OF_CONDUCT.md Data Auxiliary data
Accessible without login Plain text file connect.php Aux. Auxiliary script
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
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 Plain text file LICENSE Lic. License text
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:371
This week:0
All time:6,649
This week:309Up