Developing a smart API with a simple structure.
Create a file named Yow.php
in the path /API/Services/
and place the following code in it.
<?php class Yow extends APIService
{
// array of required params
protected $requireParams = ["FirstName", "LastName"];
function Run()
{
$firstName = $this->params["FirstName"]; // required param
$midName = $this->params["MidName"] ?? ""; // optional param
$lastName = $this->params["LastName"]; // required param
$result = "Your name is $firstName $midName $lastName";
return $result;
}
}
➕ More examples in /API/Services/
Fetch by JavaScript
fetch("https://example.com/API/GetService.php", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"ServiceName": "Yow",
"Parameters": {
"FirstName": "Mehdi",
"LastName": "RaTo"
}
})
}).then((response) => response.json()).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
➕ Look at usage.html
file for a better understanding.
{
"ServiceName": "string",
"Parameters": "object"
}
{
"IsSuccess": "boolean",
"StatusCode": "integer",
"Message": "string",
"Result": "any"
}