atk4/api

Issue with requesting api rest

rapgithub opened this issue · 6 comments

if I Use this it works; print all Json array

$api->rest('/customers', new Customers($db));

but if I use this, it does not work why? it print empty Json array

$api->rest('/customers', function() use($db) {
$c = new Customers($db);
$c->setLimit(20);
return $c;
});

any ideas?

I think I found the Issue the API.php installed with composer it is old version I have to replace it with the download and it works now!!!

composer installation must be updated!!!
thanks

Do you use develop branch in your composer.json file?
"atk4/api": "dev-develop",

yes I do, It was installed with the installation of the api using composer

I am trying to use the optional args

Like explained here:

Optional Arguments

Agile API supports various get arguments.

?sort=name,-age specify columns to sort by.
?q=search, will attempt to perform full-text search by phrase. (if supported by persistence)
?condition[name]=value, conditioning, but can also use ?name=value
?limit=20, return only 20 results at a time.
?skip=20, skip first 20 results.
?only=name,surname specify onlyFields
?ad={transformation}, apply Agile Data transformation

but it does not work!!! gives me an empty array!!! nothing... any option return the same empty array if I use optional args..

any tip what am I doing wrong?

I am trying to add this, to see if this is missing in my php file but if I include it or not the optional args does not return anything...

function args(\atk4\data\Model $m) {
if ($_GET['sort']) {
$m->sortBy($_GET['sort']);
}

if ($_GET['condition']) {
	foreach($_GET['condition'] as $key=>$val) {
        $m->addCondition($key, $val);
    }
}

if ($_GET['limit'] || $_GET['skip']) {
    $m->setLimit($_GET['limit']?:null, $_GET['skip']?:null);
}

// etc. etc...

}

any tips?
In the sample files of the API there is no examples for optional arguments or auth... I am planning to use it to feed a mobile app this api and I need first test that all working fine...

most important things are...

to be able to filter or sort or show only some fields
limit the api to get and post request...
and auth for users that are authorised are only able to use the api for making get request...

thanks

Sometimes Composer doesn't update github repos. This shit happens. @romaninsh will check that when he will return from vacation.

Speaking about some aspects which are described in readme - yes, not everything is implemented yet and some things could be implemented different than in readme. This repo still is under construction. We use it in few our projects, but only in simple way - for quickly setting up simple REST interface.

Anyway - it's all in our ToDo list and will be developed in near future. Also you can help us and send in some PRs :)

Great :) of course!