Thuta Learning
JavaScript
ProjectsProgrammingအခြေခံ

API Dashboard

JavaScriptသင်ခန်းစာ 4945 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Network ကို ထိတဲ့ code ကို request() function တစ်ခုထဲ စုပြီး status error ကို HttpError အဖြစ် throw လုပ်နိုင်ဖို့
  • Sequential await၊ Promise.all() နဲ့ Promise.allSettled() တို့ရဲ့ ကွာခြားချက်ကို ရွေးချယ်နိုင်ဖို့
  • Response data ကို aggregate မလုပ်ခင် validate လုပ်နိုင်ဖို့
  • Request ID guard နဲ့ အဟောင်းဖြစ်သွားတဲ့ response ကို ignore လုပ်နိုင်ဖို့

ရိုးရိုးလေး ရှင်းပြမယ်

ရိုးရိုးလေး ရှင်းရရင်

Dashboard ဆိုတာ ကားရဲ့ ရှေ့ခန်းက meter board နဲ့ တူပါတယ်။ အမြန်နှုန်း၊ ဆီ၊ အပူချိန် ဆိုတဲ့ meter တစ်ခုစီက sensor တစ်ခုစီကနေ data ယူပါတယ်။ ဆီ sensor ပျက်သွားရင် ကားက meter အားလုံးကို ပိတ်မပစ်ပါဘူး။ ဆီ meter မှာ warning မီးလင်းပြီး ကျန်တာတွေ ဆက်ပြနေပါတယ်။

API Dashboard ကလည်း အတူတူပါပဲ။ Users၊ posts၊ stats ဆိုတဲ့ endpoint တစ်ခုစီက panel တစ်ခုစီကို ကျွေးပါတယ်။ Request တွေကို တပြိုင်နက် ပို့ပြီး ရလာတဲ့ data ကို စစ်ကာ ဂဏန်းတွေ တွက်ပြီးမှ ပြပါတယ်။ Panel တစ်ခု ပျက်ရင် အဲဒီ panel မှာပဲ error ပြပါတယ်။

Problem → Why → Solution

ပြဿနာ: နှေးပြီး ပျက်လွယ်တဲ့ dashboard

အောက်က draft မှာ await သုံးခုကို တစ်ခုပြီးမှ တစ်ခု ဆက်ရေးထားပါတယ်။ Endpoint တစ်ခုကို 300ms ကြာရင် dashboard က 900ms ကြာမှ ပေါ်ပါတယ်။ Request တွေ တစ်ခုနဲ့တစ်ခု မမှီခိုပေမယ့် တန်းစီပြီး စောင့်နေရတာပါ။

Stats endpoint က 500 ပြန်ရင် error JSON ကို parse လုပ်ပြီး stats.totalViews က undefined ဖြစ်ကာ toLocaleString() မှာ TypeError တက်ပါတယ်။ Users နဲ့ posts data အဆင်ပြေနေပေမယ့် page တစ်ခုလုံး ဗလာ ဖြစ်သွားပါတယ်။ toLocaleString() ကို locale မပေးဘဲ ခေါ်ထားလို့ 1250 က English computer မှာ "1,250"၊ German computer မှာ "1.250" ဖြစ်ပါတယ်။ Filter ကို မြန်မြန် နှစ်ခါပြောင်းရင် နှေးတဲ့ ပထမ request က နောက်မှ ရောက်ပြီး filter အသစ်ရဲ့ result ကို ဖုံးသွားနိုင်ပါတယ်။

dashboard-draft.js
async function loadDashboard() {
  const users = await fetch("/api/users").then((r) => r.json()); // wait...
  const posts = await fetch("/api/posts").then((r) => r.json()); // ...wait again
  const stats = await fetch("/api/stats").then((r) => r.json()); // a 500? parsed anyway
  panel.innerHTML = `Users: ${users.length}, posts: ${posts.length},
    views: ${stats.totalViews.toLocaleString()}`; // "1.250" on a German PC
}

// Two quick filter changes: the older, slower reply may be drawn last.
filterSelect.addEventListener("change", loadDashboard);

အဓိက အကြောင်းရင်း

Network၊ data စစ်တာ၊ တွက်တာ၊ ဆွဲပြတာ အားလုံး function တစ်ခုထဲ ရောနေပြီး failure ဖြစ်နိုင်တဲ့ နေရာတိုင်းကို ကိုင်တွယ်ဖို့ စဉ်းစားမထားလို့ပါ။ Request သုံးခုကို အုပ်စုတစ်ခုလို "အားလုံးအောင် ဒါမှမဟုတ် အားလုံးကျ" လို့ ဆက်ဆံထားတာက panel တစ်ခုချင်းစီ လွတ်လပ်စွာ ပျက်နိုင်တဲ့ dashboard ရဲ့ သဘောနဲ့ မကိုက်ပါဘူး။

Core concept: layer ငါးခုနဲ့ settle ဖြစ်တဲ့ request တွေ

API ကို အဓိကသုံးတဲ့ app ကို layer ငါးခု ခွဲစဉ်းစားပါ။ Layer တစ်ခုစီမှာ တာဝန်တစ်ခုပဲ ရှိပြီး အောက်က layer ကိုပဲ ခေါ်ပါတယ်။ ဒီလို ခွဲထားရင် bug တစ်ခု ပေါ်တဲ့အခါ ဘယ် layer မှာ ရှာရမလဲ ချက်ချင်း သိပါတယ်။

  • Transport: request() က URL ကို ခေါ်ပြီး status 200-299 မဟုတ်ရင် status ပါတဲ့ HttpError ကို throw လုပ်ပါတယ်။ Timeout နဲ့ header တွေလည်း ဒီမှာပဲ ရှိပါတယ်။
  • Validation: data ရဲ့ shape က မျှော်လင့်ထားတဲ့အတိုင်း ဟုတ်မဟုတ် စစ်ပါတယ်။ Array ဖြစ်ရမယ့်နေရာမှာ object ရောက်လာရင် ဒီမှာ ရပ်ပါတယ်။
  • Aggregation: raw data ကနေ screen ပေါ်က ဂဏန်းတွေကို pure function တွေနဲ့ တွက်ပါတယ်။
  • State: dashboard က လက်ရှိ ဘာပြနေလဲ (loading၊ data၊ panel error) ကို သိမ်းပါတယ်။
  • Rendering: state ကို ကြည့်ပြီး ဆွဲပါတယ်။ Network ကို ဘယ်တော့မှ တိုက်ရိုက် မခေါ်ပါဘူး။

Request တွေကို ဘယ်လို စောင့်မလဲ ဆိုတာလည်း ရွေးချယ်မှုတစ်ခုပါ။ Request တစ်ခုက နောက်တစ်ခုရဲ့ result ကို လိုအပ်မှသာ တစ်ခုပြီးမှ တစ်ခု await လုပ်ပါ။ မမှီခိုတဲ့ request တွေကို တပြိုင်နက် စတင်ပြီး Promise.all() ဒါမှမဟုတ် Promise.allSettled() နဲ့ စောင့်ပါ။

နည်းလမ်းစောင့်ရတဲ့အချိန်တစ်ခု fail ရင်
await တစ်ခုပြီး တစ်ခုအချိန်အားလုံး ပေါင်းကျန်တာတွေ မစရသေးဘူး
Promise.all()အနှေးဆုံးတစ်ခုစာချက်ချင်း reject၊ result အားလုံး ဆုံး
Promise.allSettled()အနှေးဆုံးတစ်ခုစာfulfilled/rejected ကို တစ်ခုချင်း ပြန်ပေး

Dashboard အတွက် allSettled() က ပိုသင့်တော်ပါတယ်။ ဒါပေမယ့် panel တိုင်းက တန်းတူ မဟုတ်ပါဘူး။ Users နဲ့ posts မရှိရင် dashboard က အဓိပ္ပာယ်မရှိလို့ "unavailable" ပြပြီး stats တစ်ခုတည်း ပျက်ရင်တော့ ကျန်တာကို ပြပြီး stats panel မှာပဲ error ပြပါတယ်။

Layer ခွဲရင် test လုပ်ရ လွယ်ပါတယ်

summarize() က array နှစ်ခုကို လက်ခံပြီး object တစ်ခု ပြန်ပေးတဲ့ pure function ဖြစ်လို့ server၊ promise၊ timer တစ်ခုမှ မလိုဘဲ test လုပ်နိုင်ပါတယ်။ request() ကို fake နဲ့ လဲလိုက်ရင် 500၊ 404 နဲ့ ပုံစံမှားတဲ့ JSON တွေကို စက္ကန့်ပိုင်းအတွင်း စမ်းနိုင်ပါတယ်။ Layer တွေ ရောနေတဲ့ code မှာတော့ အဲဒီ case တစ်ခုချင်းစီကို စမ်းဖို့ တကယ့် server ကို ပျက်အောင် လုပ်ရပါလိမ့်မယ်။ ဒါကြောင့် ဒီ lesson ရဲ့ example တစ်ခုလုံးက network မပါဘဲ run ပါတယ်။

Mental model: sensor တစ်ခုစီ၊ meter တစ်ခုစီ
  1. Request အားလုံးကို တပြိုင်နက် စ
  2. allSettled() နဲ့ result တိုင်းကို စောင့်
  3. Fulfilled data ကို validate ပြီး တွက်
  4. Panel တစ်ခုချင်း data သို့ error ပြ

Core data (users၊ posts) ပျက်ရင် dashboard တစ်ခုလုံး unavailable ဖြစ်ပြီး optional panel (stats) ပျက်ရင် အဲဒီ panel ပဲ ထိခိုက်ပါတယ်။

အခြေခံ ပုံစံ

javascript
const results = await Promise.allSettled([
  request("/api/first"),
  request("/api/second"),
]);

for (const result of results) {
  if (result.status === "fulfilled") render(result.value);
  else renderPanelError(result.reason); // one panel fails, the rest still show
}

Request တွေကို array တစ်ခုထဲ တပြိုင်နက် စတင်ပြီး allSettled() က result တစ်ခုစီကို { status, value } ဒါမှမဟုတ် { status, reason } အဖြစ် ပြန်ပေးပါတယ်။ Result တစ်ခုချင်းစီကို သီးသန့် ကိုင်တွယ်ပါ။

Stats endpoint ပျက်နေချိန်နဲ့ ကောင်းနေချိန် dashboard

fakeServer object က path တစ်ခုစီအတွက် status နဲ့ body ကို သတ်မှတ်ထားပါတယ်။ ပထမ run မှာ /api/stats က 500 ပြန်ပြီး ဒုတိယ run မတိုင်ခင် ပြင်ပေးလိုက်ပါတယ်။ Output မှာ users နဲ့ posts panel တွေက နှစ်ခါလုံး ပေါ်ပြီး stats panel ပဲ ပြောင်းသွားတာကို ကြည့်ပါ။

dashboard.js
// dashboard.js - transport, validation, aggregation and text rendering. No DOM.
const fakeServer = {
  "/api/users": { status: 200, body: [
    { id: 1, name: "Aung Kyaw", active: true },
    { id: 2, name: "Su Su", active: true },
    { id: 3, name: "Min Min", active: false },
  ] },
  "/api/posts": { status: 200, body: [
    { id: 1, userId: 1, likes: 10 },
    { id: 2, userId: 1, likes: 5 },
    { id: 3, userId: 2, likes: 15 },
  ] },
  "/api/stats": { status: 500, body: { error: "database timeout" } },
};

class HttpError extends Error {
  constructor(status, path) {
    super(`HTTP ${status} from ${path}`);
    this.status = status;
  }
}

// Transport: one place that talks to the network (faked here).
async function request(path) {
  const route = fakeServer[path] ?? { status: 404, body: null };
  await new Promise((resolve) => setTimeout(resolve, 10));
  if (route.status < 200 || route.status > 299) throw new HttpError(route.status, path);
  return route.body;
}

// Validation: refuse data the rest of the code cannot handle.
function expectArray(value, name) {
  if (!Array.isArray(value)) throw new TypeError(`${name} should be an array`);
  return value;
}

// Aggregation: pure functions from raw data to the numbers on screen.
function summarize(users, posts) {
  const active = users.filter((u) => u.active).length;
  const likes = posts.reduce((sum, p) => sum + p.likes, 0);
  const avg = posts.length ? likes / posts.length : 0;
  return { users: users.length, active, posts: posts.length, likes, avg };
}

async function loadDashboard() {
  const [users, posts, stats] = await Promise.allSettled([
    request("/api/users").then((d) => expectArray(d, "users")),
    request("/api/posts").then((d) => expectArray(d, "posts")),
    request("/api/stats"),
  ]);
  if (users.status === "rejected" || posts.status === "rejected") {
    return ["Dashboard unavailable: core data failed to load"];
  }
  const s = summarize(users.value, posts.value);
  const lines = [
    `Users: ${s.users} (${s.active} active, ${s.users - s.active} inactive)`,
    `Posts: ${s.posts}, likes: ${s.likes}, avg: ${s.avg.toFixed(1)}`,
  ];
  if (stats.status === "fulfilled") {
    lines.push(`Views: ${stats.value.totalViews.toLocaleString("en-US")}`);
  } else {
    lines.push(`Stats panel: unavailable (${stats.reason.message})`);
  }
  return lines;
}

console.log("-- stats endpoint failing --");
(await loadDashboard()).forEach((line) => console.log(line));

fakeServer["/api/stats"] = { status: 200, body: { totalViews: 1250 } };
console.log("-- all endpoints healthy --");
(await loadDashboard()).forEach((line) => console.log(line));

Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်

  1. An error that carries the statusclass HttpError extends Error {

    Error ကို extend လုပ်ပြီး status ကို property အဖြစ် သိမ်းပါတယ်။ UI က error.status === 401 ဆို login page၊ 500 ဆို "နောက်မှ ပြန်ကြိုးစားပါ" လို့ ခွဲပြနိုင်ပါတယ်။

  2. Validate before you computerequest("/api/users").then((d) => expectArray(d, "users")),

    Server က array အစား object ပြန်ပို့ရင် summarize() ထဲမှာ filter is not a function လို ရှုပ်ထွေးတဲ့ error မတက်ခင် "users should be an array" ဆိုတဲ့ ရှင်းလင်းတဲ့ error နဲ့ ဒီမှာ ရပ်ပါတယ်။

  3. All three start togetherconst [users, posts, stats] = await Promise.allSettled([

    Request သုံးခုလုံး ချက်ချင်း စတင်ပြီး allSettled() က အားလုံး settle ဖြစ်တဲ့အထိ စောင့်ပါတယ်။ ဘယ်တစ်ခုမှ reject ဖြစ်လို့ ကျန်တာတွေ ပျောက်မသွားပါဘူး။

  4. Core data versus optional panelsif (users.status === "rejected" || posts.status === "rejected") {

    Users နဲ့ posts က core data ဖြစ်လို့ တစ်ခုခု ပျက်ရင် dashboard တစ်ခုလုံး unavailable ပြပါတယ်။ Stats ကိုတော့ ဒီ condition ထဲ မထည့်ထားလို့ ပျက်ရင် panel တစ်ခုတည်း ထိခိုက်ပါတယ်။

  5. A fixed locale for numbersstats.value.totalViews.toLocaleString("en-US")

    Locale ကို ရှင်းရှင်း ပေးထားလို့ ဘယ် computer မှာ run ပါစေ "1,250" ပဲ ထွက်ပါတယ်။ User ရဲ့ locale အတိုင်း ပြချင်ရင်တော့ test တွေမှာ locale ကို သတ်မှတ်ပေးရပါမယ်။

You should see
-- stats endpoint failing --
Users: 3 (2 active, 1 inactive)
Posts: 3, likes: 30, avg: 10.0
Stats panel: unavailable (HTTP 500 from /api/stats)
-- all endpoints healthy --
Users: 3 (2 active, 1 inactive)
Posts: 3, likes: 30, avg: 10.0
Views: 1,250

Browser အတွက် transport အစစ်

Example ထဲက request() က fake server ကို ခေါ်ပေမယ့် browser အတွက် version မှာ contract တူတူပါပဲ။ Path လက်ခံ၊ status မကောင်းရင် HttpError throw၊ ကောင်းရင် parse လုပ်ထားတဲ့ JSON ပြန်ပေးပါတယ်။ Layer တွေ ခွဲထားလို့ ဒီ function တစ်ခုကို လဲလိုက်ရုံနဲ့ validation၊ aggregation၊ rendering code တွေ တစ်ကြောင်းမှ ပြင်စရာ မလိုပါဘူး။

AbortSignal.timeout() က အချိန်ကျော်သွားရင် request ကို ဖျက်ပြီး TimeoutError နဲ့ reject လုပ်ပါတယ်။ Timeout မထားရင် ပြန်မဖြေတဲ့ server က loading spinner ကို အဆုံးမရှိ လည်နေစေပါတယ်။

api.js
// api.js - the browser version of request(): same contract, real network
async function request(path, { timeoutMs = 8000 } = {}) {
  const res = await fetch(path, {
    headers: { Accept: "application/json" },
    signal: AbortSignal.timeout(timeoutMs), // give up on a server that hangs
  });
  if (!res.ok) throw new HttpError(res.status, path);
  return res.json();
}

လက်တွေ့ project တွေမှာ

လက်တွေ့ project တွေမှာ

Admin panel၊ analytics page၊ monitoring screen တွေမှာ ဒီ pattern ကို နေ့တိုင်း သုံးပါတယ်။ Team တွေက request() ကို project တစ်ခုလုံးအတွက် API client တစ်ခုအဖြစ် ထားပြီး auth token ထည့်တာ၊ timeout၊ retry လို အလုပ်တွေကို အဲဒီတစ်နေရာမှာပဲ လုပ်ပါတယ်။

Status code တစ်ခုစီကို အဓိပ္ပာယ်ရှိရှိ ကိုင်တွယ်ပါ။ 401 ဆို session ကုန်သွားလို့ login ပြန်ဝင်ခိုင်းပါ။ 404 ဆို data မရှိကြောင်း ပြပါ။ 409 ဆို တခြားသူက အရင် ပြင်သွားလို့ data ကို reload လုပ်ခိုင်းပါ။ 500 နဲ့ 503 ဆိုရင် ခဏနေမှ ပြန်ကြိုးစားနိုင်ပါတယ်။ Test တွေမှာလည်း happy path တစ်ခုတည်း မဟုတ်ဘဲ နှေးတဲ့ response၊ JSON ပုံစံမှားတာ၊ 401၊ 500 နဲ့ response အစီအစဉ် ပြောင်းပြန် ရောက်တာတွေကို fake server နဲ့ စမ်းပါ။

အမှားများ

ဖြစ်လေ့ရှိတဲ့ အမှားများ

Partial failure ရှိနိုင်တဲ့နေရာမှာ Promise.all() သုံးတာ

Promise.all() က promise တစ်ခု reject ဖြစ်တာနဲ့ ချက်ချင်း reject ဖြစ်ပြီး အောင်မြင်ခဲ့တဲ့ result တွေကို ပြန်မပေးပါဘူး။ Optional panel တစ်ခုကြောင့် dashboard တစ်ခုလုံး error screen ဖြစ်သွားပါတယ်။ Panel တွေ လွတ်လပ်ရမယ်ဆိုရင် allSettled() ကို သုံးပါ။

Promise ကို ဆောက်ပြီးမှ တစ်ခုချင်း await လုပ်တာ

const a = await getA(); const b = await getB(); လို့ ရေးရင် getB() က getA() ပြီးမှ စပါတယ်။ မမှီခိုတဲ့ request တွေကို array ထဲမှာ တပြိုင်နက် စပြီးမှ စောင့်ပါ။ Network tab မှာ request တွေ လှေကားထစ်လို တန်းစီနေရင် ဒီအမှားရဲ့ လက္ခဏာပါ။

Response အဟောင်းက state အသစ်ကို ဖုံးတာ

Filter ပြောင်းတိုင်း request အသစ် ပို့ရင် response တွေက ပို့တဲ့အစီအစဉ်အတိုင်း ပြန်ရောက်မယ်လို့ အာမခံချက် မရှိပါဘူး။ Request တစ်ခုစီကို ID ပေးပြီး နောက်ဆုံး ID ရဲ့ result ကိုပဲ apply လုပ်ပါ၊ ဒါမှမဟုတ် အဟောင်းကို AbortController နဲ့ cancel လုပ်ပါ။

Mini challenge

Latest-only guard ကို ရေးပါ

Async function တစ်ခုကို wrap လုပ်ပြီး နောက်ဆုံးခေါ်ခဲ့တဲ့ call ရဲ့ result ကိုပဲ "fresh" လို့ သတ်မှတ်ပေးတဲ့ createLatestOnly() ကို ရေးပါ။ Delay မတူတဲ့ fake search နဲ့ user က မြန်မြန် ရိုက်တာကို အတုလုပ်ပြီး stale result တွေ screen ပေါ် မရောက်တာကို ပြပါ။

  • Call တစ်ခုစီက counter ကနေ ID ကိုယ်ပိုင် ရရပါမယ်
  • Result က { stale, value } ပုံစံ ဖြစ်ရပါမယ်
  • Stale ဖြစ်နေတဲ့ call ရဲ့ error ကို throw မလုပ်ဘဲ { stale: true, error } ပြန်ပေးရပါမယ်
  • နောက်ဆုံး call ရဲ့ error ကိုတော့ throw လုပ်ပြီး user ကို ပြရပါမယ်
latest-only.js
function createLatestOnly(asyncFn) {
  // TODO: keep a counter of how many calls have started
  return async (...args) => {
    // TODO: give this call its own id from the counter
    // TODO: await asyncFn(...args) and return { stale, value }
    //       where stale is true when a newer call has started since
    // TODO: if it throws and is stale, return { stale: true, error } instead;
    //       if it throws and is still the latest, re-throw
  };
}

// TODO: a fakeSearch(term) that resolves after a per-term delay (setTimeout)
// TODO: onType(term) that applies fresh results and logs ignored stale ones
// TODO: start "s" (slow) and "su" (fast) together with Promise.all

ရလဒ်: "su" ကို apply လုပ်ပြီး "s" ကို stale အဖြစ် ignore လုပ်ပါမယ်။ "min" ကို apply လုပ်ပြီး "zz" ရဲ့ error ကို ignore လုပ်ပါမယ်။ နောက်ဆုံး "zz" တစ်ခုတည်းကို ခေါ်တဲ့အခါမှ error ပြပြီး screen မှာ Min Min ကျန်နေရပါမယ်။

အရိပ်အမြွက် ကြည့်ရန်

Wrapper အပြင်ဘက်မှာ let latest = 0 ထားပြီး call တိုင်း const id = ++latest လုပ်ပါ။ await ပြီးချိန်မှာ id !== latest ဆိုရင် အဲဒီကြားထဲ call အသစ် ရောက်လာခဲ့ပြီလို့ အဓိပ္ပာယ်ရပါတယ်။

အဖြေ ကြည့်ရန်
latest-only.js
function createLatestOnly(asyncFn) {
  let latest = 0;
  return async (...args) => {
    const id = ++latest; // this call's ticket number
    try {
      const value = await asyncFn(...args);
      return { stale: id !== latest, value };
    } catch (error) {
      if (id !== latest) return { stale: true, error }; // nobody waits for it
      throw error;
    }
  };
}

// Fake API: each term answers after its own delay, like a real network.
const people = ["Su Su", "Aung Kyaw", "Min Min", "Su Myat"];
const delays = { s: 120, su: 20, zz: 80, min: 10 };

function fakeSearch(term) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (term === "zz") reject(new Error("HTTP 500"));
      else resolve(people.filter((p) => p.toLowerCase().includes(term)));
    }, delays[term]);
  });
}

const search = createLatestOnly(fakeSearch);
const screen = { results: [] };

async function onType(term) {
  try {
    const outcome = await search(term);
    if (outcome.stale) return console.log(`ignored stale "${term}"`);
    screen.results = outcome.value;
    console.log(`applied "${term}": ${screen.results.join(", ")}`);
  } catch (error) {
    console.log(`error for "${term}": ${error.message}`);
  }
}

// The user types "s" then "su"; the slower "s" answer arrives last.
await Promise.all([onType("s"), onType("su")]);
// A failing request that is already obsolete must not show an error.
await Promise.all([onType("zz"), onType("min")]);
// A failing request that is still the latest must show its error.
await onType("zz");
console.log("screen shows:", screen.results.join(", "));

Quick Quiz 1 / 3

Request သုံးခုကို Promise.all() နဲ့ စောင့်နေပြီး ဒုတိယ request က reject ဖြစ်သွားပါတယ်။ ပထမနဲ့ တတိယ result တွေကို ဘာဖြစ်မလဲ။

Quick Quiz 2 / 3

Example ထဲမှာ /api/posts က 500 ပြန်ရင် loadDashboard() က ဘာပြန်ပေးမလဲ။

Quick Quiz 3 / 3

User က filter ကို A ကနေ B ကို မြန်မြန် ပြောင်းပါတယ်။ A ရဲ့ request က B ထက် နှေးပါတယ်။ Guard မရှိရင် screen က ဘာပြမလဲ။

မှတ်ထားရမယ့် အချက်များ

  • API app ကို transport၊ validation၊ aggregation၊ state၊ rendering ဆိုတဲ့ layer တွေ ခွဲပါ
  • request() တစ်ခုထဲမှာ status စစ်ပြီး HttpError နဲ့ status ကို ဆက်ပို့ပါ
  • မမှီခိုတဲ့ request တွေကို တပြိုင်နက် စပြီး panel လွတ်လပ်ရင် allSettled() သုံးပါ
  • toLocaleString() ကို locale ရှင်းရှင်း ပေးပြီး ခေါ်ပါ
  • Request ID guard နဲ့ response အဟောင်းကို ignore လုပ်ပါ

MDN — Fetch API — MDN Web Docs

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

API Dashboard | Thuta Learning