#Can you make multiple requests in one loader?

1 messages · Page 1 of 1 (latest)

hexed marsh
#

Hey, what requests do you mean? You can make multiple fetch requests, call multiple db endpoints etc. 🤔 You can kinda do whatever you want or would do elsewhere in there.

deep idol
hexed marsh
#

You can await the user id from remix-auth and then make your fetch

split musk
#

You can make as many requests as you want inside a loader (as I understand it). I like to think of the loader as just "code that the server should run before the pages loads for the user", so you can kinda put whatever (and however much) you want inside there

hexed marsh
#

yea it's like a "normal" API endpoint, just embedded in your route file

deep idol
split musk
#

What should bits look like instead?

deep idol
# split musk What should `bits` look like instead?
  "data": [
    {
      "user_id": "158010205",
      "user_login": "tundracowboy",
      "user_name": "TundraCowboy",
      "rank": 1,
      "score": 12543
    },
    {
      "user_id": "7168163",
      "user_login": "topramens",
      "user_name": "Topramens",
      "rank": 2,
      "score": 6900
    }
  ],
  "date_range": {
    "started_at": "2018-02-05T08:00:00Z",
    "ended_at": "2018-02-12T08:00:00Z"
  },
  "total": 2
}``` or atleast be null
split musk
#

I would try and use a service like Postman to double check the output of the API request first

#

Rather than doing it in Remix

#

If you query that Twitch API and look at what it returns (make sure to do the auth stuff) that'll help you first figure out if it's a Remix problem or an API problem

deep idol
#

Tried the exact same request in postman and got the required output, If I console log the json output of the fetch in the loader I can see the whole response but nothing actually resembling the right response

#

I've managed to get a bit further now I can see the bits request results in a 200 ok, but again there is nothing resembling what the response should be

#

I am going to open a new question for this