Skip to content

Instantly share code, notes, and snippets.

@gustavohenrique
Created May 16, 2016 01:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gustavohenrique/53a983755a4af447ec386629ebab576b to your computer and use it in GitHub Desktop.
Save gustavohenrique/53a983755a4af447ec386629ebab576b to your computer and use it in GitHub Desktop.
Your storage model is not your object model is not your resource model is not your representation model.
MY DATA MODEL IS NOT MY OBJECT MODEL
first, the data model (SQL, DocStore, FileSystem) is indepdendent of the object model in the program. for example, i might store customer information (including contact info, financial profile, and order history) in a database. and i might have an object model in my code that includes a customerSummary object. this customerSummary is not a data table. it is made up of details from each of the three data tables, tho.
MY OBJECT MODEL IS NOT MY RESOURCE MODEL
my HTTP resources might take into account the *context* of the user (e.g. visitor, customer, sales rep, admin) and offer different resources for each of them that exposes select customer data. e.g. the /public/customers/ resource might show a list of customer names only with a link to see detail if security context supports that. and the /sales/customer/ resource might list each customer along with recent order history and links to contact that customer directly, update the order history, etc. and the /private/customer/ resource might list only customer information that should be seen by the logged in customer (along with pointers to order history, the ability to start a new order, make a sales inquiry, etc. none of these resources exist in the internal programming object model -- they are, however, aggregates of a handful of internal objects.
MY RESOURCE MODEL IS NOT MY REPRESENTATION MODEL
my HTTP resources might support content-negotiation for responses. for example, my customers might be able to request their order history (/private/customer/orders/) in CSV format or the standard HTML display. the HTML version might first show summaries of each order w/ a link to details of each. But the CSV response might show all the details in a single listing (listing order lines w/ orderid to show the relationships, etc.).
the point to all this is that HTTP only has something to say about the last two elements (RESOURCE and REPRESENTATION) and when HTTP says PUT is for replacing a resource that may have no direct correlation to any single internal OBJECT or DATA-RECORD. and there might even be a case where executing a PUT on a CSV representation of a resource will include different data elements than an HTML representation of that same resource.
Author: Mike Amundsen <amundsen.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment