Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Get one for multiple identifier

Not applicable

Hi everyone,

I have a resource with multiple unique identifier

For example /dogs, with id, name and dna is unique.

how should a RESTful design for get one id, name and dna looks like?

Some of my thought:

1. Using query string:

/dogs/{id}
/dogs?name={name}
/dogs?dna={dna}

This is not consistent, where /dogs/{id} return a single entity, the others return a collection (of one)

2. use a type parameter

/dogs/{id}?type={id|name|dna}

the type if not provided will be "id" by default.

this make it consistent, all return single entity if found and 404 if not found.

3. sub resource

/dogs/{id}
/dogs/name/{name}
/dogs/dna/{dna}

hmm, not RESTful ?

Thank you

0 6 343
6 REPLIES 6