Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Running a serverless function just returns a Response with a readable stream instead of data

I have the following serverless function

import type { APIGatewayEvent, Context } from 'aws-lambda'
import { logger } from 'src/lib/logger'
const request = require('request')

export const handler = async (event: APIGatewayEvent, context: Context) => {
  const result = await sendToApi(event)

  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      data: { result },
    }),
  }
}

const sendToApi = function (event) {
  return new Promise((resolve) => {
    logger.info('Invoked twitter function')


    const { twitter } = JSON.parse(event.body)

    const options = {
      method: 'GET',
      url: `https://api.twitter.com/2/users/by/username/${twitter}?user.fields=profile_image_url`,
      headers: {
        Authorization: `Bearer ${process.env.TWITTER_BEARER_TOKEN}`,
      },
      contentType: 'application/json',
    }

    request(options, function (error, response) {
      if (error) throw new Error(error)
      console.log('monkeyboogers', response.body)
      resolve(response.body)
    })
  })
}

and the following front end code that calls the function

const profile = await fetch(
      `${window.location.origin}/.redwood/functions/twitter`,
      {
        method: 'POST',
        body: JSON.stringify({ twitter: twitter }),
      }
    )
    console.log(await profile)
    setTwitter(await profile)

The problem is in the server it console logs the data just fine but in the front end it console logs the following

body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "http://localhost:8910/.redwood/functions/twitter"

and inside the body is just ReadableStream

I know I am missing some key piece, but I am not sure 100% what that is. Thanks for any help ahead of time.l I appreciate it a lot.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!