1. Go to this page and download the library: Download anshu-krishna/api-framework library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anshu-krishna / api-framework example snippets
// file: codebase-root/public/index.php
Config::$dev_mode = true; // Set to false in production
Config::$zlib = false; // Set to true if you want to compress the output
// See Krishna\API\Config for more options
// Initialize the server
Server::init(
func_base_path: __DIR__ . '/../api-funcs-base',
);
// Start executing api request
Server::execute();
// file: codebase-root/api-funcs-base/Ping.php
// This API expects either no parameters or a single parameter 'msg' of type string;
// See DataValidator in the notes below to see more examples of possible signatures
use Krishna\API\Func;
// Set the signature of the function
Func::set_signature([
'?msg' => 'string',
]);
// Set the definition of the function
Func::set_definition(function(array $data, string $funcName) {
if(!array_key_exists('msg', $data)) {
return 'Hello; No message received';
}
return 'Hello; Message received: ' . $data['msg'];
});
Config::$dev_mode = false; // This will disable the debug and meta information in the response