Problem Querying REST API from React + Node

Solved
Highlighted
Excursionist
15 1 3

I figured it out!

 

For anyone else with the same issue, the key is adding the router to the server:

 

  server.use(router.routes());  // THIS LINE IS KEY
  server.use(verifyRequest());
  server.use(async (ctx) => {
    await handle(ctx.req, ctx.res);
    ctx.respond = false;
    ctx.res.statusCode = 200;
    return
  });
1 Like
Highlighted
Excursionist
26 1 1

I understand this was solved, however, I am wondering what the following is:

getCollections = () => 

 I tried to implement the code but said getCollections() wasn't defined, I am new to app development so would be great if someone could assist me. I don't understand how you call an API that is in the backend from the frontend.

0 Likes
Highlighted
Excursionist
26 1 1

I got mine working, however, I need to do it for POST not GET does anyone know how to do that? Changing GET > POST doesn't seem to work.

0 Likes
Shopify Partner
123 4 51

@benjk not sure exactly which portion are your referring to - swapping GET for POST in the koa-router calls should do the trick, unless there's something extra you're doing in the POST request.

 

Can you post your code?

0 Likes