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

Include Meta Information on the response json #4

Closed
ngcammayo opened this issue Apr 21, 2014 · 4 comments
Closed

Include Meta Information on the response json #4

ngcammayo opened this issue Apr 21, 2014 · 4 comments

Comments

@ngcammayo
Copy link

Hi my I suggest if you can add the meta information from the response. The purpose was to use this on javascript tables such as jquery DataTable as a source. If you can make another method to have a parameter or a flag that indicate if the meta information be included in the response.

Again thanks for this wonderful API handler.

@ngcammayo
Copy link
Author

Sample format would be like this:

[
{
"meta_total_count": 10,
"meta_filter_count": 0,
"meta_response":
{
"id": "1",
"code": "est",
"name": "Est et.",
"status": "0",
"created_by": "minus",
"updated_by": null,
"created_at": "2014-04-19 02:03:37",
"updated_at": "2014-04-19 02:03:37",
"deleted_at": null
}
}
]

@marcelgwerder
Copy link
Owner

I thought a lot about this and I decided to first support the meta information in the http headers. However I may indeed add this optional feature in the future. There are multiple ways to do this.
I could support an additional parameter in getResponse() or an option in the package config which allows the developer to decide what he wants. Or use a flag like _config=envelope where the client can decide In which form he wants the data.

This of course isn't implemented right now. With the tools available right now you can still manually implement an envelope. This is however not that clean but it works:

$result = ApiHandler::parseMultiple($foo, array('foo', 'bar'));
$builder = $result->getBuilder();
$metaProviders = $result->getMetaProviders();
$response = array();

foreach($metaProviders as $provider) {
    if($provider->getTitle() == 'Meta-Total-Count') $response['meta_total_count'] = $provider->get();    
    else if($provider->getTitle() == 'Meta-Filter-Count') $response['meta_filter_count'] = $provider->get();
}

$response['data'] = $builder->get();

return $response; 

@ngcammayo
Copy link
Author

Thanks, it just shows the flexibility that you have implemented this handler in a way to make it open for modification.

Once again thank you for considering my request.

@marcelgwerder
Copy link
Owner

Lets keep this issue open. I'll close it when there is a more sophisticated solution.

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

No branches or pull requests

2 participants