PHP Classes

spf PHP API Class JSON Library: Handle API calls with parameters passed as JSON

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 43 All time: 10,838 This week: 524Up
Version License PHP version Categories
spfapi 1.0Custom (specified...7HTTP, Web services, PHP 7
Description 

Author

This class can handle API calls with parameters passed as JSON.

It checks the current HTTP request GET and POST parameters to extract parameters that may be passed in JSON format to the server to be handled by this class.

The class can return the name of the requested API command, parameter values and uploaded files.

It can also generate the response by setting the response status code and response data.

Picture of silvio
  Performance   Level  
Name: silvio <contact>
Classes: 3 packages by
Country: Italy Italy
Age: ???
All time rank: 3674144 in Italy Italy
Week rank: 192 Up8 in Italy Italy Up

Example

<?php
/*
 * Copyright 2020 Silvio Sparapano <ssilvio@libero.it>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
namespace api;
include_once
'spfApi.class.php';


$spfapi = new spfApi();

$command = $spfapi->getApiCommand();
error_log("command: ".$command);

$spfapi->setResponseCode(spfApi::SPF_API_RC_INVALID_COMMAND);


if(
$command == "getTest"){
   
$apiParams = $spfapi->getApiParam();
   
error_log("apiParams: ".print_r($apiParams,true));
   
   
$name = $spfapi->getPostParam("name",true);
   
error_log("name: ".$name);
   
   
$logo = $spfapi->getPostParam("logo");
   
error_log("logo: ".print_r($logo,true));
   
   
$spfapi->setResponseCode(spfApi::SPF_API_RC_OK);
   
$spfapi->setResponseValue("Welcome", $name);
}

if(
$command == "getTestForm"){
   
$file1 = $spfapi->getUploadFileInfo("myFile1");
   
error_log("myFile1: ".print_r($file1,true));
   
   
$file1Def = $spfapi->renameTempFileWithExtension("myFile1");
   
error_log("myFile1Def: ".print_r($file1Def,true));
   
   
$spfapi->setResponseCode(spfApi::SPF_API_RC_OK);
   
$spfapi->setResponseValue("Uploaded file", $file1Def);
}


echo(
$spfapi->getResponse());


  Files folder image Files (4)  
File Role Description
Accessible without login Plain text file Licence.txt Lic. License
Plain text file spfApi.class.php Class Class implementation
Accessible without login Plain text file spfApiSample.php Example Example application using spfApi.
Accessible without login Plain text file testapi.html Data Test page.

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:43
This week:0
All time:10,838
This week:524Up