Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Page query param added to collection self link #90

Open
Wilt opened this issue Mar 4, 2015 · 3 comments
Open

Page query param added to collection self link #90

Wilt opened this issue Mar 4, 2015 · 3 comments

Comments

@Wilt
Copy link
Contributor

Wilt commented Mar 4, 2015

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.

@weierophinney
Copy link
Member

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.

@Wilt
Copy link
Contributor Author

Wilt commented Apr 9, 2015

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.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-hal; a new issue has been opened at laminas-api-tools/api-tools-hal#20.

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

No branches or pull requests

2 participants