0

I have created an endpoint that searches for a particular user based on their email address if one is provided as a query parameter on a GET request: ...person/search?email=. I would like to extend this endpoint so that it can also optionally accept an SMS number, something like ...person/search?sms=. However, I do not want people to be able to search using both - only ?email= or ?sms=.

Am I going about this the wrong way? Should I set up an entirely different endpoint to search by SMS number?

Ben Melito
  • 131
  • 2
  • 12

1 Answers1

0

If you have

person/search?email=misteryperson@gmail.com&sms=0779529293493

Then on your server you can have logic to decide how this is interpreted. I am using my experience and intuition to tell you that this is restful based on my experience of developing APIs.

On the server side you could then have your logic to determine how to retrieve, filter the data set based on this GET request.

If you want to have business logic to determine only one of these can be used, then you can decide which one takes precedent or throw an exception if both are provided by using your code.

I think that this is the best approach, because

  • What if you add a third way to obtain a person in the future? Are you going to add another end point?
  • What if you want to unify them at some point, you will have to merge 3 end points
  • If you update the way one works, you may have to update the way the other works

There's a good stackoverflow question here, where they discuss the best way to define a search end point

Max Carroll
  • 4,441
  • 2
  • 31
  • 31