REST API to check if an object exists

Viewed 7183

I have currently a webservice that load an object which looks like /object/load?id=100, the problem is that my object is really huge and it takes a long time to get the full response of the webservice just to see if the object exists or not.

What is the best pratice here ?

  • Creating a new webservice /object/exists?id=100 thats only use HTTP status code (200 if object exists, 404 if not) ?

  • Add parameter to the /object/load webservice to return only simplified object ?

2 Answers

If you are only interested in existence, or knowing in advance how the API will respond if you do a real GET request, HTTP actually has a built-in method for that: HEAD.

I'd recommend creating a new method within your existing web service. Name that method 'Exists' or something similar, and make sure that it is a HttpGET method.

You could then pass in the ID of the object you want to check, then within the method just do a check to see if the object exists. If the object exists you should return true, else return false.

Related