RESTful API – Best Practices for Calls with Variations

apinamingrest

How do I name API endpoints that serve the same entity in different ways and still adhere to the RESTful API guidelines?

Let's consider I'd like to get a customer with ALL his details.

  • I just expose a GET endpoint at address "/customer".

Now I'd like to check if a customer with a particular customerId exists.

  • What do I do now? How do I name the endpoint?

Possible solutions I've thought:

  • I expose another GET endpoint at address "/customerNameCheck". This feels SOAP-y.

  • I keep the GET endpoint at address "/customer" which accepts an extra parameter called type which could take values type="check"/type="fullCustomer" which will determine the flow of events on the server and serve the appropriate response.


Both of my solutions feel like violations of general naming conventions.

Any ideas?

Best Answer

As per comments, the URL to get details of a customer is /customer/{customerId}.

To check if a customer ID already in use without retrieving all the details, you can query the same URL using a HEAD request.

Related Topic