2

first of all fuck this stupid website and deleting your rant if you aren't signed up
second of all fuck fetch
curl gives me a readable json object
axios gives me a readable json object
fetch gives me what should be a readable json object, but looks more like a set in python instead
[{"id":"1"},{"id":"2"}] curl and axios reply with this
meanwhile fetch
{
[
{"id":"1"},
{"id":"2"}
],
{various symbol objects}
}
how am I supposed to get my data out of a fetch? I see people call response[0] or using some strange amalgamation of
fetch().then().then((data) => {}) but data in this results in an unresolved promise for some inexplicable reason. (nextjs)
also fuck nextjs I want to go back to hardcoding everything in html
also fuck modern web development and businesses in general, they ruined the internet.

Comments
  • 1
    JSON.parse(resp.text()) or smth. Should never give a different result than the axios fucker does.

    Nice first rant. Kudos

    Edit: just const txt = await data?
  • 1
    That's what `res.json()` is for?
  • 0
    const response = await fetch('thing')

    const jsonBody = await response.json()

    If my code above is not wrong, this will get your JSON thing as an actual object. The thing is, the response variable above, awaited by the fetch() promise, contains a "body" object which really is a stream (if I recall correctly), so that's why you gotta read it asynchronously. The json() method does the work of reading the whole JSON body stream and converting it into a JS object for you. (It'll fail parsing if the return isn't a JSON, though)

    Also, since it's a stream, I THINK if you try to read the same JSON body out of response again, it'll no longer be there, because it was pulled out from the stream in your previous call.

    It's something like that, hopefully I'm right AND explained in a clear way.
  • 0
    @nururururu >it'll no longer be there

    Imagine you had some shit stuck in a pipe, waiting to be removed in one end of the pipe. You open that end, and collect the shit with your hand. If you then try to remove shit again in the same pipeline of promises, no shit will be there. That's the nature of streams, one of which your network request is at the application level.

    Hopefully I'm not too wrong here.
Add Comment