I have an API with a custom search over half a dozen fields, something along the lines of the following, although may also include sensitive data as I use the same approach for the same type of search elsewhere
- Username
- Firstname
- Lastname
- Department
I'm generally using a RESTful approach, so retrieving users would be something like the following for a list of users, or a single user
GET /user
GET /user/1
For the search, however, I'm slightly baffled as to how to allow this. My original intention was to use JSON in the request body, eg
{
"username": "someuser",
"department": "sales"
}
I can't use the request body as would seem logical (and as I use for POST etc actions), though, because it isn't supported by Chrome as far as I can tell (or at least, not by the PostMan addon, which we use for testing)
As such, what's the best way to perform this search?
The options I see
Use a header
Which seems like the "wrong" use of headers, but also the closest to the origial request body
Use parameters in the URL
eg
GET /user?username=someuser&department=sales
But that gets messy with the controller (using C# Web API), because I can't leave items blank. So the request would be more like this, unless I had a ton of overridden methods to handle the different permutations. This seems... messy
GET /user?username=someuser&email=&firstname=&lastname=&department=
Perhaps more importantly, it leaves a little too much visible "over the shoulder": this is within a healthcare setting, and while there are unavoidable times where things are displayed, I would rather keep this to a minimum (the data itself is, naturally, SSL encrypted during transmission)
Use a different HTTP verb
I could use POST or some other verb, which would work but is counter-intuitive and goes against both the RESTful approach (as far as I can tell) and my own standards within the project, so could be confusing.
Has anyone else run into this? What's the "official" or best way to handle it?