Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API
Composer
class is responsible for that
iCompose
interface
Luracast\Restler\Defaults::$composeClass = ‘MyOwnCompose’;
hi
i need little advise on annotations:
Is it possible to annotate that i'm returning an array of models, and show model attributes on explorer under "Response Class"
Eg:
/**
* @return array (@class Users)
*/
public function index()
{
return [
new User(),
new User(),
];
}
Thanks!
Looking at the live examples it doesn't seem like they are using require_once
to import the APIClasses, but in my application I have to otherwise it seems like $r->addAPIClass('Foo')
doesn't make that routable. How do I prevent this from happening:
<?php
include_once './vendor/autoload.php';
include_once 'Foo.php';
include_once 'Bar.php';
include_once 'Baz.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Foo');
$r->addAPIClass('Bar');
$r->addAPIClass('Baz');
$r->handle();
i.e. how do I stop needing to include every one of my API classes.
addAPIClass
threw an exception if it can't find an APIClass. I probably spent 2 hours going through the source trying to figure out why it wasn't routing until I realized the include
was missing.
/**
* @status 201
* @url POST upload
* @format UploadFormat
* @access public
* @throws RestException
*/
function upload()
{
$media = CmsMedias::createMedia($_FILES['file']);
header("Content-Type: application/json");
echo json_encode(["media_id" => $media->getMediaId()]);
exit();
}
return ["media_id" => $media->getMediaId()];
Hello, I cannot access the command line on my server so I cannot install Composer and Restler in a conventional way. I created a local web server and I set up everything. Accessing http://localhost/HomebrewLand/public/examples/_001_helloworld/index.php/say/hello works correctly.
Now I uploaded the project to my server, and when I write the same URL, I have the following error:
Warning: Class 'Luracast\Restler\Restler' not found in /var/www/legtux.org/users/devnoname120/www/HomebrewLand/vendor/restler.php on line 6
Fatal error: Class 'Luracast\Restler\Restler' not found in /var/www/legtux.org/users/devnoname120/www/HomebrewLand/public/examples/_001_helloworld/index.php on line 18
Do you know how I could fix it?
If I modify the following line of vendor/restler.php
if (is_readable(__DIR__ . '/autoload.php')) {
to
if (false && is_readable(__DIR__ . '/autoload.php')) {
then it uses the other loader and it works. But it doesn't seem to be a proper solution (and could create issues later), so I would like to fix my issue anyway.
I got this model-code so far:
<?php
namespace API\Models;
use Luracast\Restler\Data\ValueObject;
/**
* Class Client
*
* A demo for model usage
*
* @package API\Models
*/
class Client extends ValueObject
{
/**
* @var int $id The id of the client
*/
public $id;
/**
* @var string $surname The surname of the client
*/
public $surname;
/**
* @var string $firstName The first name of the client
*/
public $firstName;
/**
* @var string $emailAddress The e-mail address of the client {@type email}
*/
public $emailAddress;
/**
* @var int $age The age of the client
*/
public $age;
}
Then the API Class very simple:
<?php
namespace API\Clients;
use API\Models\Client;
/**
* Class Clients
*
* Demonstrate the Model Usage
*
* @package API\Clients
*/
class Clients
{
/**
* Retrieves a client by using the Client-Model
*
* @param int $id
*
* @return Client
*/
public function getClient($id)
{
$client = new Client();
$client->id = $id;
$client->age = 42;
$client->surname = "Doe";
$client->firstName = "John";
$client->emailAddress = "john.doe@umbrella.inc";
return $client;
}
/**
* Creates client by using the Client-Model
*
* @param Client $client
*
* @return Client
*
* @status 201
*/
public function postClient($client)
{
return $client;
}
}
This "works", but there is no validation done on the Model-Object passed by the POST?