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:

  1. are own entities related otherwise independent class, or
  2. 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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -