How to properly response to a Non-Resource type?!

I have an endpoint for checking the username availability.

How would you design the response of that endpoint. Normally I will say if the username is available or not but I am having a hard time thinking the data schema for that endpoint response

I see two ways.

  1. Use another API for that task. You talk to https://api.example.com for normal business and use https://util.example.com for small tasks that are not based on resource manipulation.

  2. Make a request to something like https://api.example.com/users?filter[username]=myusername and if a resource is returned, then that means that the username is taken.

I would attempt a user creation with a “dry-run” meta:

POST /users
{
  data: {attributes: {username: "johnsmith"}},
  meta: {dry-run: true}
}

and expose the validation errors as if it was an actual creation (or “Accepted” if it wasn’t)