question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to return the response data as a string?

See original GitHub issue

mock.onGet('/api').reply(200, '{"test": 5}')

response.data is a JS object that looks like {test: 5} instead of a string.

Is there any way to force the response to be a string?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
jeroensakcommented, Nov 23, 2018

i’d also like to use an array instead of an object. The second parameter of reply should be any type

0reactions
jamespearsoncommented, Aug 23, 2022

try this mock.onGet().replyOnce((config) => { config.transformResponse = [function (data) { return JSON.stringify(data) }] return [ 200, {test: 5} ] })

This won’t work if the transformResponse is the thing you want to test.

At the moment, it appears a custom transformResponse on the request is called, but the data isn’t passed to it. I’m going to investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to return string as a response to http request
It seems $http finds it difficult to parse the invalid JSON data in the response. We have produces = {MediaType.
Read more >
Response.text() - Web APIs - MDN Web Docs
It returns a promise that resolves with a String . The response is always decoded using UTF-8. Syntax. text()
Read more >
How to store Response.ok().built result into a String variable
Just return Response object as your method was supposed to return Response object.
Read more >
Reading an HTTP Response Body as a String in Java
We can retrieve and send data via the CloseableHttpClient class. To create an instance of it with the default configuration, we can use...
Read more >
Describing Responses - Swagger
A response is defined by its HTTP status code and the data returned in ... JSON is the most common format for data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found