Recommendation for user chosen unique ids for resources: precheck resource existence

Hi,
I couldn’t find any recommendation for what I see as a very common use case, which has unfortunately led to a lot of bikeshed in my team :frowning:
The use case is allowing users to create resources, enforcing unique ids.

First of all, a simple system could be to just send an http creation request and have the server respond with an http error code, but this has the downside that the id conflict check is delayed to when all data has been entered by the user. This leads to a worse UI for 99.999% of the cases where the unique id can be checked and feedback provided immediately (of course the unique id must be checked again when actually creating the resource, and this check succeeds almost all the time if the precheck has suceeded. An error is thrown otherwise and the user must chose another id)

So an existence precheck is justified in many cases I think. For this, I think the classic implementations are:

  • performing a HEAD request on the resource canonical URL. Since it’s HEAD, only the http response headers can be used to answer. if you use 200/404, then you get scary colors in browser console logs when you call this and the check says the resource doesn’t exist. Also it can be argued that it’s easier to make mistakes when programming the client because most libraries automatically translate http error code to exceptions, which can cause control flow to jump non locally and that’s more complicated and a return value and local control flow. Using 200/204 fixes this but feels like warping the http codes. Are there other more adapted http codes ?
  • performing a request on a separate dedicated url (e.g. /resources/:name/exists, or /check/:name ) responding with 200 and with “true” or “false” in the body or some variation. This is more like an RPC than REST.
  • using a more general search system for resources (/resources?id=… or /search?id=… or something). This has the drawback that it invites to create a full blown search system when you only need an existence check.

Are there other solutions ? Does {json:api} have a stance on this ?
Personally I would prefer a system that doesn’t use 4XX codes to signal that the user is choosing an existing ID because the goal of the form is precisely to allow the user to create a unique id, so it’s normal and expected that the user tries various already existing ids.

Thanks in advance,
Jon