0
0
Remixframework~20 mins

Resource routes for APIs in Remix - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Remix Resource Routes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Remix resource route loader?

Given this loader function in a Remix resource route, what will the response body be?

Remix
export async function loader() {
  return new Response(JSON.stringify({ message: "Hello API" }), {
    headers: { "Content-Type": "application/json" },
  });
}
A{"message":"Hello API"}
BHello API
C{"data":"Hello API"}
Dundefined
Attempts:
2 left
💡 Hint

Remember that the loader returns a Response with JSON stringified data.

state_output
intermediate
2:00remaining
What HTTP method does this Remix resource route action handle?

Consider this Remix resource route action function. Which HTTP method will trigger this action?

Remix
export async function action({ request }) {
  if (request.method === "POST") {
    return new Response("Created", { status: 201 });
  }
  return new Response("Method Not Allowed", { status: 405 });
}
AGET
BPOST
CPUT
DDELETE
Attempts:
2 left
💡 Hint

Check the condition inside the action function for the request method.

📝 Syntax
advanced
2:30remaining
Which option correctly defines a Remix resource route with a DELETE action?

Choose the correct Remix resource route code snippet that handles DELETE requests in the action function.

A
export async function action({ request }) {
  if (request.method === DELETE) {
    return new Response(null, { status: 204 });
  }
  return new Response("Not Allowed", { status: 405 });
}
B
export async function action({ request }) {
  if (request.method === "delete") {
    return new Response(null, { status: 204 });
  }
  return new Response("Not Allowed", { status: 405 });
}
C
export async function action({ request }) {
  if (request.method === "DELETE") {
    return new Response(null, { status: 204 });
  }
  return new Response("Not Allowed", { status: 405 });
}
D
export async function action({ request }) {
  if (request.method = "DELETE") {
    return new Response(null, { status: 204 });
  }
  return new Response("Not Allowed", { status: 405 });
}
Attempts:
2 left
💡 Hint

Check the case sensitivity and syntax of the method comparison.

🔧 Debug
advanced
2:30remaining
Why does this Remix resource route loader cause a runtime error?

Analyze this loader function. Why will it cause a runtime error when called?

Remix
export async function loader() {
  const data = await fetch('/api/data');
  return data.json();
}
AThe URL '/api/data' is invalid causing a network error
Bfetch is not defined in the server environment causing ReferenceError
CThe loader returns a Response object instead of JSON causing a type error
Ddata.json() returns a promise but loader does not await it causing a runtime error
Attempts:
2 left
💡 Hint

Consider the async nature of data.json() and how the loader returns its result.

🧠 Conceptual
expert
3:00remaining
Which option best describes the purpose of resource routes in Remix APIs?

Choose the statement that correctly explains the role of resource routes in Remix API design.

AResource routes handle data fetching and mutations without rendering UI, focusing on HTTP methods for RESTful APIs
BResource routes are used to render React components with server-side data fetching
CResource routes automatically generate UI forms for CRUD operations
DResource routes are only for static file serving and do not support dynamic data
Attempts:
2 left
💡 Hint

Think about how resource routes differ from UI routes in Remix.