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

Page query param added to collection self link #20

Open
weierophinney opened this issue Dec 31, 2019 · 2 comments
Open

Page query param added to collection self link #20

weierophinney opened this issue Dec 31, 2019 · 2 comments

Comments

@weierophinney
Copy link
Contributor

When I request a collection route while using pagination I get the links rendered as follows:

    "_links": {
        "self": {
            "href": "http://hostname/api/v1/users?page=1"
        },
        "first": {
            "href": "http://hostname/api/v1/users"
        },
        "last": {
            "href": "http://hostname/api/v1/users?page=2"
        }
    },

The url I requested was http://hostname/api/v1/users. The self link in the response gets a pagination param while the first page doesn't. Shouldn't it be the other way around?
So like this:

    "_links": {
        "self": {
            "href": "http://hostname/api/v1/users"
        },
        "first": {
            "href": "http://hostname/api/v1/users?page=1"
        },
        "last": {
            "href": "http://hostname/api/v1/users?page=2"
        }
    },

On the client I would like to dynamically create links to my other pages by adding a page query parameter including a page number to the collection self link. Right now I cannot do this because the self link already holds a page param. I would expect the self link to be a base collection link.


Originally posted by @Wilt at zfcampus/zf-hal#90

@weierophinney
Copy link
Contributor Author

Actually, neither the first nor the self page should have the parameter at that point. I'm not quite sure how we'll address that, though.


Originally posted by @weierophinney at zfcampus/zf-hal#90 (comment)

@weierophinney
Copy link
Contributor Author

Currently I solved it by customizing the injectPaginationLinks method and added a current link:

        // current link
        $link = new Link('current');
        $link->setRoute($route);
        $link->setRouteParams($params);
        $link->setRouteOptions(ArrayUtils::merge($options, array(
            'query' => array('page' => $page),
        )));
        $links->add($link, true);

And on top of that I removed the page param from the self route...
Resulting in this _links array:

    "_links": {
        "self": {
            "href": "http://hostname/api/v1/users"
        },
        "current": {
            "href": "http://hostname/api/v1/users?page=1"
        },
        "first": {
            "href": "http://hostname/api/v1/users?page=1"
        },
        "last": {
            "href": "http://hostname/api/v1/users?page=2"
        }
    },

Not sure if this could be of any help, but for now it did the job for me.


Originally posted by @Wilt at zfcampus/zf-hal#90 (comment)

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

1 participant