You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

In our What is a resource? article we noted that a resource is digital content which can be represented by various media types. Most of the time this will be text based media (e.g., HTML, JSON, XML). However, there will be situations when the resource needs to be represented by binary media. Here are a few possible use cases:

  • A PDF version of a customer invoice.
  • A JPEG image of a barcode.
  • An MPEG video of assembly instructions.

The SRP HTTP Framework includes a routine called Picture_API. It includes logic that returns a graphic image associated with the indicated sample contact. Regardless of the specific binary media type, the basic steps for returning binary media in your API are the same.

Step One: Read the Binary Data

Your binary data needs to be read into a variable. Typically this will be done using the OSRead statement. Here is the relevant code from the Picture API:

OSRead PictureBinary from PicturePath then
    // Other logic goes here.
end

Step Two: Set the Response Body.

As with text based media, use the SetResponseBody service to identify the content to be returned to the caller.


  • No labels