We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to handle request with string query

Hi everyone,

I'm making a web api for administration purpose. And the first function is list all users with pagination.

I tried to create route like this https://example.com/v1/users/{page}, it seems fine

But if I need to make a function to get user detail, it will be like https://example.com/v1/users/{user_id} And these 2 routes will be conflict

So I think a good way must be https://example.com/v1/users?page={page} where {page} is an integer.

How can I handle request like that? I tried to create request like that but every from ? is ignored.

Thank you very much



7.9k

I would like to make this format https://example.com/v1/users/{param}

Param is in json it include everything, like search criteria or page. Its more easier :)

edited Mar '15

I would like to use below format for list users with pagination. users defines the multiple users.

GET https://example.com/v1/users/{param}

and for user detail

GET https://example.com/v1/user/{param}

User difines the single user.



18.9k
Accepted
answer

I would like to use below format for list users with pagination. users defines the multiple users.

GET https://example.com/v1/users/{param}

and for user detail

GET https://example.com/v1/user/{param}

User difines the single user.

Thank you, but I'm trying to follow restful conventions, 2 uri for a resource. (/users/ to list all and /users/id to list detail)

Using both "user" and "users" is not a good choice.

After a couple of hours research, I find a way: I just need to use $page = $request->getQuery("page", "int");