I'm in the process of making an API more RESTful. At the moment I have an endpoint like this:
/booking?bookingid=123
I have updated the endpoint to be more RESTful like this:
/bookings/123
A booking looks a bit like this:
{
"bookingId":123,
"people":[
{
"personId":0,
"name":{
"forename":"Jon",
"surname":"Smith"
}
},
{
"personId":1,
"name":{
"forename":"Sarah",
"surname":"Jones"
}
}
]
}
I want to only return a booking if the booking contains a particular surname and to return Not Found if the surname doesn't exist on the booking.
The way I am looking to implement this is by adding a query string:
/bookings/123?surname="Jones"
This would return the booking above as Sarah's surname is "Jones" the booking would also be returned with a query string surname with value "Smith".
The first problem I have with this is that if a property of surname were added to the booking object it looks like the query is against that and the other problem I have is that it's querying against a single entity and not a list, is this a RESTful approach and if not then what is a better approach?