RestAPI naming convention for boolean endpoints

Viewed 1242

It is a trivial question but I cannot find an answer. Lets say I have an endpoint that simply checks if a user exists within a certain group and returns a boolean. What should the RestAPI path look like?

/api/user/{id}/exists/{group}

/api/user/{id}/in/{group}

/api/user/{id}/is_assigned/{group}

/api/user/{id}/exists_within/{group}

I feel like the API path name should read organically, but I also don't like using an underscore. What do you guys suggest?

1 Answers

REST doesn't care what spellings you use for your identifiers.

PUT /abff1822-71aa-4147-9b91-18a8a4f1bf6c
Content-Type: application/json

true
PUT /abff1822-71aa-4147-9b91-18a8a4f1bf6c
Content-Type: application/json

false
GET /abff1822-71aa-4147-9b91-18a8a4f1bf6c

Old school POST also "just works"

POST /abff1822-71aa-4147-9b91-18a8a4f1bf6c
Content-Type:application/x-www-form-urlencoded

value=true

URI are a lot like variable names - the machines don't care, and because they don't care you can follow whatever local spelling conventions make sense.

Related