Skip to Content

Scripting example - Convert binary to response to text

This Plugin script example was used with a Microsoft Azure REST API, and works with a raw Binary response. The Plugin essentially converts the API endpoint response into something that Vinyl can consume/read.

For example, if the REST API endpoint returns something like:


Then the Plugin converts the response to something that Vinyl can read, like:

"Message": "success"

Script example

#r "Newtonsoft.Json.dll"
using System;
using System.Net.Http;
using Newtonsoft.Json;
// Read the response content
var messageBytes = await Response.Content.ReadAsByteArrayAsync();
var message = Convert.ToBase64String(messageBytes);
// Wrap the message in a json formatted text
message = JsonConvert.SerializeObject(new { Message = message });
// Replace the response content with the formatted json
Response.Content = new StringContent(message, null, "application/json");