RESTful enums. string or Id?
Posted
by
GazTheDestroyer
on Stack Overflow
See other posts from Stack Overflow
or by GazTheDestroyer
Published on 2012-12-14T12:16:30Z
Indexed on
2012/12/17
5:03 UTC
Read the original article
Hit count: 122
I have a RESTful service that exposes enums.
Should I expose them as localised strings, or plain integers?
My leaning is toward integers for easy conversion at the service end, but in that case the client needs to grab a list of localised strings from somewhere in order to know what the enums mean. Am I just creating extra steps for nothing?
There seems to be little information I can find about which is commonly done in RESTful APIs.
EDIT:
OK. Let's say I'm writing a website that stores information about people's pets. I could have an AnimalType enum
0 Dog
1 Cat
2 Rabbit
etc.
When people grab a particular pet resource, say /pets/1
, I can either provide a meaningful localised string for the animal type, or just provide the ID and force them to do another look up via a /pets/types
resource.
Or should I provide both?
© Stack Overflow or respective owner