1

I wonder what saying good practices create REST API. Should or not I create URI which will allow get e.g. several specific users?

For example I mean:

/usermanagement/users/{j_goldman,wafik,morder}

And this uri will be returns 3 objects users for j_goldman, wafik and morder.

Erii Asari
  • 165
  • 1
  • 2
  • 8

2 Answers2

0

You can do this but it won't be restful IMHO. If you really need to do this you should think about remodeling your resource selections say, all three users you want to get belong to a particular group with id 111. Then you can do something like /groups/111 GET. If you cannot then I guess you should stick with restful solution and use three API calls to get users separately.

hspandher
  • 15,934
  • 2
  • 32
  • 45
  • I wonder about the case when someone want to get information from system about several particular users or whatever others resource. Someone may wish get information about e.g. 2, 5 or 10 users, it not always this same group of users. – Erii Asari Jun 13 '15 at 14:52
  • You can easily model that request on the group resource such that members are specified by API user itself. – hspandher Jun 13 '15 at 17:13
0

What you are doing is searching for a specific set of users. With a query parameter within your URL, you can achieve this.

To return a single user (id is 5):

/usermanagement/users/5

To return all users:

/usermanagement/users

To return a set of users based on search:

/usermanagement/users?username=

That way, your API is open to searching by a specified criteria which can also be extended.

Say, you wish to search by location:

/usermanagement/users?location=

Say, you wish to combine these:

/usermanagement/users?username={criteria}&location={criteria}

You may also want to expose a search endpoint itself:

/usermanagement/search

You might find other options here too:

RESTful URL design for search

Community
  • 1
  • 1
JamesB
  • 7,774
  • 2
  • 22
  • 21
  • In my system user is identified about username (maybe it is wrong but let's leave it alone for now). I'm not talking about search. I wonder about the case when someone want to get information from system about several particular users or whatever others resource. – Erii Asari Jun 13 '15 at 14:45
  • But what defines those particular users? You have to tell the API something about them in order to get them back. IMO, you are defining a search criteria. – JamesB Jun 13 '15 at 15:27