user7560542
user7560542

Reputation: 547

How would one create a restful URL for two different types on the same entity?

So let's say you have a table called Requests. It contains requests that you submitted and also requests that other have submitted, but that you need to approve.

To load your requests, the RESTful url would probably be:

www.myapp.com/requests

For a separate link, that loads requests that I need to approve, what would the URL look like?

This is all I could come up with, but it looks sloppy:

www.myapp.com/requests?awaitingapproval=true

Upvotes: 2

Views: 248

Answers (1)

Quentin C
Quentin C

Reputation: 1893

What you are doing is a good implementation of filtering in a RESTful API.

This article can help you: https://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/

Since you are checking for a boolean, you could implement it like this also:

www.myapp.com/requests?fields=waitingapproval

which gives you the possibility to add other fields:

www.myapp.com/requests?fields=waitingapproval,urgent

Example from the site:

GET /cars?color=red Returns a list of red cars

GET /cars?seats<=2 Returns a list of cars with a maximum of 2 seats

Upvotes: 1

Related Questions