Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 http://example.com/v1/users/{page}, it seems fine

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

So I think a good way must be http://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



5.8k

I would like to make this format http://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 http://example.com/v1/users/{param}

and for user detail

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

User difines the single user.



11.6k
Accepted
answer

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

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

and for user detail

GET http://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");