How to model a global resource in a REST API? -
rest seems focus on collections of resources -- lists of things. how should 1 model exists once in system? , more simple. suppose modeled system classroom, has students, 1 teacher, , door either open or closed. how 1 model door? i'm thinking following:
get , post operations supported. https://<ipaddress>/classroom/door_status returns 200 if successful, response containing: doorstatus - string - value of door status, either "open" or "closed" post https://<ipaddress>/classroom/door_status specify attribute of: doorstatus - string - value of desired door status, "open" or "closed" returns 201 if status modified.
delete fail.
a classroom of course have multiple doors, bear me moment. , of course building classrooms has multiple classrooms. again bear me.
next, might add light_status resource classroom. given likely, should start "global_properties" resource, have doorstatus , lightstatus properties instead.
thanks suggestions, help, or (especially) examples. ...alan
i don't think there in rest makes single instance entities illegal or undesirable. said, in particular example, need evaluate if door , light:
- are own entities related otherwise independent class, or
- are attributes or contained objects of class without own identity , existence depends on existence of class
the second option 1 seems more reasonable me. if accept it, can return light , door status part of class properties:
get /class -- returns class attributes, including light , door status put /class -- updates class attributes, including light , door status
Comments
Post a Comment