Herr Derb
Herr Derb

Reputation: 5367

How to pass filter arguments to GET requests in REST APIs?

I'm building a RESTful webservice:

Everything as it should be.

Those clients have a property called authorized. On my web UI to manage those, I have separated tables for authorized and unauthorized clients. Of course, I do not want to load all the clients from the server just to display the unauthorized ones.

The question is, how could I filter the client over a RESTful URL? As I want to do a proper RESTful API, query parameters are not an option.

I already thought about additionally doing GET /unauthorizedClients and GET /authorizedClients but this seems not right, as I still would use DELETE/clients/%clientId%` to remove one client.

I couldn't think of a pleasing approach for this problem. Any tips on how this could be solved are welcome.

Upvotes: 0

Views: 1805

Answers (2)

cassiomolin
cassiomolin

Reputation: 130957

I'm just wondering what prevents you from using query parameters. They are the most appropriate way to filter a collection of resources in REST APIs. Using query parameters won't make your API less RESTful.

You could have the following:

  • Authorized: GET /clients?status=authorized
  • Unauthorized: GET /clients?status=unauthorized

Another option is:

  • Authorized: GET /clients/authorized
  • Unauthorized: GET /clients/unauthorized

You really should consider query parameters though.

Upvotes: 2

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

I would go with /clients/unauthorized and /clients/authorized. You need to taylor resource URIs like directories.

This way, there's nothing wrong with deleting clients against the /client/[id] resource.

Upvotes: 0

Related Questions