Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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:

...

The SRP HTTP Framework includes a routine called Picture_API. It includes logic that returns the a graphic images image associated with the indicated sample contacts. This article will break it down into the two basic stepscontact. Regardless of the specific binary media type, the basic steps for returning binary media in your API are the same.

Step One: Load 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:

Code Block
languagebp
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.