Quick Answer

A resource (aka web resource) is digital content returned by a server that is referenced by a URL. The source of this content could be anything: a text file, a PDF document, a database row, or a combination of content derived from different sources. The SRP HTTP Framework provides optimized services to return MultiValue data as a serialized JSON object (also referred to as a resource object).

Digging Deeper

There are practical and academic answers to this question. Both are important.

The Practical Answer

Given that this question is being asked within the context of using OpenInsight as a source for RESTful APIs and that OpenInsight is primarily a database that is exposed through procedures that enforce business rules, a resource is most often derived from a database row. The specific column data contained in the resource will vary based on other factors. Likewise, the format of the resource (e.g., JSON, XML, etc.) can change based on the requirements of the client and the capability of the server.

It is a mistake to relate resources to database tables too closely. Doing so will restrict your ability to expose resources in ways that might not fit well within your database model. Resources and databases should be loosely coupled so each one can evolve freely without breaking how the APIs work.

Because resources are the most significant content returned from an API, we have provided the HTTP_Resource_Services module to help. By default, the SRP HTTP Framework returns resources in JSON format (aka Resource Object):

{
   "address":"6649 N Blue Gum St",
   "birthdate":"",
   "city":"New Orleans",
   "company":"Benton, John B Jr",
   "county":"Orleans",
   "email":"jbutt@gmail.com",
   "first_name":"James",
   "last_name":"Butt",
   "notes":"",
   "phone":[
      {
         "phone_number":"(504) 621-8927",
         "phone_type":"Phone 1"
      },
      {
         "phone_number":"(504) 845-1427",
         "phone_type":"Phone 2"
      }
   ],
   "state":"LA",
   "url":"http://www.bentonjohnbjr.com",
   "zip":"70116"
}

The Academic Answer

Let's also answer another question, "Why do we use the word resource?" The answer is because our method for referencing a resource, i.e., a URL, stands for Uniform Resource Locator. Since we are building web APIs that rely upon the standards for URIs (or URL) and the standards for HTTP, we want to use the terms already employed.

HTTP standards indicate that "a resource could be anything". URI standards tell us that the term "is used in a general sense for whatever might be identified by a URI". While these might not seem overly helpful, they really are important because they caution us against preconceived notions of what a resource is or is not.

In our practical answer above, there is a warning about tightly binding resources to database tables. Resources can be abstractions of anything meaningful. They are often aggregates of digital information pulled from multiple sources (which is why one-to-one relationships between resources and tables is discouraged). OpenInsight developers already have some experience with this concept: Calculated Columns. A calculated column provides a way for tables to draw information from other sources, thus providing the client with richer data than is physically stored in a specific database table. One resource returned by a URI can be a combination of different database rows from different tables, OS files such as images and PDFs, or data pulled from another technology like SQL. To the client this is just a resource and it has no knowledge of the underlying ways the server manages the source content.

  • No labels