Return a custom image from a URL


Get Started

Not the template you're looking for? Browse more.

About the template


This template fetches an image of a kitten and then sends back the image with a HTTP response. This template demonstrates how to work with Generic HTTP Event listeners and how to send back binary data as a response. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnFetchKittenHttpEvent
Sync HTTP Event

README


๐Ÿ“‹ Overview

This template fetches an image of a kitten ๐Ÿฑ and then sends back the image with a HTTP response. This template demonstrates how to work with Generic HTTP Event listeners and how to send back binary data as a response.

๐Ÿ–Š๏ธ Setup

  • Configure Sync HTTP Event listener.

๐Ÿš€ Usage

Grab the URL that you should have received when setting up the Generic HTTP Event Listener, open that URL in your browser, after successful event processing you should get back a random kitten image.

TypeScriptOnFetchKittenHttpEvent

import { HttpEventRequest, HttpEventResponse } from '@sr-connect/generic-app/events/http';
import { convertBufferToText } from '@sr-connect/convert';

/**
 * This function fetches a kitten image by using Fetch API (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API),
 * and then sends back the image with HTTP response
 *
 * @param event Object that holds Sync HTTP Event event data
 * @param context Object that holds function invocation context data
 */
export default async function(event: HttpEventRequest, context: Context): Promise<HttpEventResponse> {
    // Fetch a kitten image using Fetch API
    const response = await fetch('https://placecats.com/300/200');

    // Check if the response is OK
    if (!response.ok) {
        // If not then throw an error
        throw Error(`Unexpected response: ${response.status}`)
    }

    // Convert the binary data from response into base64 encoded string
    const body = convertBufferToText(await response.arrayBuffer(), 'base64');

    // Return back a response
    return {
        status: 200,
        body,
        isBase64: true
    }
}
Documentation ยท Support ยท Suggestions & feature requests