Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with requesting api rest #7

Open
rapgithub opened this issue Jul 31, 2018 · 6 comments
Open

Issue with requesting api rest #7

rapgithub opened this issue Jul 31, 2018 · 6 comments
Assignees

Comments

@rapgithub
Copy link

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?

@rapgithub
Copy link
Author

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

@DarkSide666
Copy link
Member

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

@rapgithub
Copy link
Author

rapgithub commented Aug 1, 2018

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

@rapgithub
Copy link
Author

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

@DarkSide666
Copy link
Member

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 :)

@rapgithub
Copy link
Author

Great :) of course!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants