[{"data":1,"prerenderedAt":2265},["ShallowReactive",2],{"blog-en-multilingual-nuxt4-prerendering":3,"blog-related-en-multilingual-nuxt4-prerendering":784},{"id":4,"title":5,"author":6,"body":7,"date":768,"description":769,"extension":770,"featured":771,"image":772,"meta":773,"navigation":188,"path":774,"readingTime":210,"seo":775,"slug":776,"stem":777,"tags":778,"__hash__":783},"blog\u002Fblog\u002Fen\u002Fmultilingual-nuxt4-prerendering.md","How to Build a Lightning-Fast Multilingual Website with Nuxt 4 & Static Prerendering","Adam Abdel-Djamal",{"type":8,"value":9,"toc":759},"minimark",[10,14,22,35,38,46,57,65,129,450,452,459,469,475,605,607,614,620,629,676,678,682,685,744,755],[11,12,13],"p",{},"Building a multilingual website often turns into a performance and SEO compromise: slow dynamic routing, duplicated canonical URLs, broken browser redirect cookies, and plummeting Lighthouse scores.",[11,15,16,17,21],{},"When building this portfolio, my goal was strict: ",[18,19,20],"strong",{},"5 languages (EN, FR, DE, ES, JA), sub-50ms static load times, perfect hreflang sitemaps, and 100\u002F100 Lighthouse scores",".",[11,23,24,25,28,29,21],{},"In this guide, I share the exact configuration that achieves zero-runtime static prerendering with ",[18,26,27],{},"Nuxt 4"," and ",[18,30,31],{},[32,33,34],"code",{},"@nuxtjs\u002Fi18n",[36,37],"hr",{},[39,40,42,43],"h2",{"id":41},"_1-the-core-routing-strategy-prefix_except_default","1. The Core Routing Strategy: ",[32,44,45],{},"prefix_except_default",[11,47,48,49,52,53,56],{},"By default, multilingual setups often create redundant redirects for the root URL (",[32,50,51],{},"\u002F"," -> ",[32,54,55],{},"\u002Fen","), adding a costly 200ms TTFB penalty.",[11,58,59,60,64],{},"The optimal strategy is ",[18,61,62],{},[32,63,45],{},":",[66,67,68,81,93,105,117],"ul",{},[69,70,71,72,74,75,74,78],"li",{},"English (default): ",[32,73,51],{},", ",[32,76,77],{},"\u002Fportfolio",[32,79,80],{},"\u002Fblog",[69,82,83,84,74,87,74,90],{},"French: ",[32,85,86],{},"\u002Ffr",[32,88,89],{},"\u002Ffr\u002Fportfolio",[32,91,92],{},"\u002Ffr\u002Fblog",[69,94,95,96,74,99,74,102],{},"German: ",[32,97,98],{},"\u002Fde",[32,100,101],{},"\u002Fde\u002Fportfolio",[32,103,104],{},"\u002Fde\u002Fblog",[69,106,107,108,74,111,74,114],{},"Spanish: ",[32,109,110],{},"\u002Fes",[32,112,113],{},"\u002Fes\u002Fportfolio",[32,115,116],{},"\u002Fes\u002Fblog",[69,118,119,120,74,123,74,126],{},"Japanese: ",[32,121,122],{},"\u002Fja",[32,124,125],{},"\u002Fja\u002Fportfolio",[32,127,128],{},"\u002Fja\u002Fblog",[130,131,136],"pre",{"className":132,"code":133,"language":134,"meta":135,"style":135},"language-typescript shiki shiki-themes github-light github-dark","\u002F\u002F nuxt.config.ts\nexport default defineNuxtConfig({\n  modules: ['@nuxtjs\u002Fi18n', '@nuxtjs\u002Fsitemap'],\n\n  i18n: {\n    langDir: 'locales\u002F',\n    defaultLocale: 'en',\n    strategy: 'prefix_except_default',\n    detectBrowserLanguage: {\n      useCookie: true,\n      cookieKey: 'i18n_redirected',\n      redirectOn: 'root',\n      alwaysRedirect: false,\n      fallbackLocale: 'en',\n    },\n    locales: [\n      { code: 'en', language: 'en-US', file: 'en.json', name: 'English' },\n      { code: 'fr', language: 'fr-FR', file: 'fr.json', name: 'Français' },\n      { code: 'de', language: 'de-DE', file: 'de.json', name: 'Deutsch' },\n      { code: 'es', language: 'es-ES', file: 'es.json', name: 'Español' },\n      { code: 'ja', language: 'ja-JP', file: 'ja.json', name: '日本語' },\n    ],\n  },\n})\n","typescript","",[32,137,138,147,165,183,190,196,208,219,230,236,248,259,270,281,291,297,303,332,357,382,407,432,438,444],{"__ignoreMap":135},[139,140,143],"span",{"class":141,"line":142},"line",1,[139,144,146],{"class":145},"sJ8bj","\u002F\u002F nuxt.config.ts\n",[139,148,150,154,157,161],{"class":141,"line":149},2,[139,151,153],{"class":152},"szBVR","export",[139,155,156],{"class":152}," default",[139,158,160],{"class":159},"sScJk"," defineNuxtConfig",[139,162,164],{"class":163},"sVt8B","({\n",[139,166,168,171,175,177,180],{"class":141,"line":167},3,[139,169,170],{"class":163},"  modules: [",[139,172,174],{"class":173},"sZZnC","'@nuxtjs\u002Fi18n'",[139,176,74],{"class":163},[139,178,179],{"class":173},"'@nuxtjs\u002Fsitemap'",[139,181,182],{"class":163},"],\n",[139,184,186],{"class":141,"line":185},4,[139,187,189],{"emptyLinePlaceholder":188},true,"\n",[139,191,193],{"class":141,"line":192},5,[139,194,195],{"class":163},"  i18n: {\n",[139,197,199,202,205],{"class":141,"line":198},6,[139,200,201],{"class":163},"    langDir: ",[139,203,204],{"class":173},"'locales\u002F'",[139,206,207],{"class":163},",\n",[139,209,211,214,217],{"class":141,"line":210},7,[139,212,213],{"class":163},"    defaultLocale: ",[139,215,216],{"class":173},"'en'",[139,218,207],{"class":163},[139,220,222,225,228],{"class":141,"line":221},8,[139,223,224],{"class":163},"    strategy: ",[139,226,227],{"class":173},"'prefix_except_default'",[139,229,207],{"class":163},[139,231,233],{"class":141,"line":232},9,[139,234,235],{"class":163},"    detectBrowserLanguage: {\n",[139,237,239,242,246],{"class":141,"line":238},10,[139,240,241],{"class":163},"      useCookie: ",[139,243,245],{"class":244},"sj4cs","true",[139,247,207],{"class":163},[139,249,251,254,257],{"class":141,"line":250},11,[139,252,253],{"class":163},"      cookieKey: ",[139,255,256],{"class":173},"'i18n_redirected'",[139,258,207],{"class":163},[139,260,262,265,268],{"class":141,"line":261},12,[139,263,264],{"class":163},"      redirectOn: ",[139,266,267],{"class":173},"'root'",[139,269,207],{"class":163},[139,271,273,276,279],{"class":141,"line":272},13,[139,274,275],{"class":163},"      alwaysRedirect: ",[139,277,278],{"class":244},"false",[139,280,207],{"class":163},[139,282,284,287,289],{"class":141,"line":283},14,[139,285,286],{"class":163},"      fallbackLocale: ",[139,288,216],{"class":173},[139,290,207],{"class":163},[139,292,294],{"class":141,"line":293},15,[139,295,296],{"class":163},"    },\n",[139,298,300],{"class":141,"line":299},16,[139,301,302],{"class":163},"    locales: [\n",[139,304,306,309,311,314,317,320,323,326,329],{"class":141,"line":305},17,[139,307,308],{"class":163},"      { code: ",[139,310,216],{"class":173},[139,312,313],{"class":163},", language: ",[139,315,316],{"class":173},"'en-US'",[139,318,319],{"class":163},", file: ",[139,321,322],{"class":173},"'en.json'",[139,324,325],{"class":163},", name: ",[139,327,328],{"class":173},"'English'",[139,330,331],{"class":163}," },\n",[139,333,335,337,340,342,345,347,350,352,355],{"class":141,"line":334},18,[139,336,308],{"class":163},[139,338,339],{"class":173},"'fr'",[139,341,313],{"class":163},[139,343,344],{"class":173},"'fr-FR'",[139,346,319],{"class":163},[139,348,349],{"class":173},"'fr.json'",[139,351,325],{"class":163},[139,353,354],{"class":173},"'Français'",[139,356,331],{"class":163},[139,358,360,362,365,367,370,372,375,377,380],{"class":141,"line":359},19,[139,361,308],{"class":163},[139,363,364],{"class":173},"'de'",[139,366,313],{"class":163},[139,368,369],{"class":173},"'de-DE'",[139,371,319],{"class":163},[139,373,374],{"class":173},"'de.json'",[139,376,325],{"class":163},[139,378,379],{"class":173},"'Deutsch'",[139,381,331],{"class":163},[139,383,385,387,390,392,395,397,400,402,405],{"class":141,"line":384},20,[139,386,308],{"class":163},[139,388,389],{"class":173},"'es'",[139,391,313],{"class":163},[139,393,394],{"class":173},"'es-ES'",[139,396,319],{"class":163},[139,398,399],{"class":173},"'es.json'",[139,401,325],{"class":163},[139,403,404],{"class":173},"'Español'",[139,406,331],{"class":163},[139,408,410,412,415,417,420,422,425,427,430],{"class":141,"line":409},21,[139,411,308],{"class":163},[139,413,414],{"class":173},"'ja'",[139,416,313],{"class":163},[139,418,419],{"class":173},"'ja-JP'",[139,421,319],{"class":163},[139,423,424],{"class":173},"'ja.json'",[139,426,325],{"class":163},[139,428,429],{"class":173},"'日本語'",[139,431,331],{"class":163},[139,433,435],{"class":141,"line":434},22,[139,436,437],{"class":163},"    ],\n",[139,439,441],{"class":141,"line":440},23,[139,442,443],{"class":163},"  },\n",[139,445,447],{"class":141,"line":446},24,[139,448,449],{"class":163},"})\n",[36,451],{},[39,453,455,456],{"id":454},"_2-preventing-broken-links-with-uselocalepath","2. Preventing Broken Links with ",[32,457,458],{},"useLocalePath()",[11,460,461,462,465,466,468],{},"Never hardcode internal navigation links (",[32,463,464],{},"\u003CNuxtLink to=\"\u002Fcontact\">","). If a visitor on the French version (",[32,467,86],{},") clicks an unlocalized link, they are forcefully knocked back to the English version.",[11,470,471,472,64],{},"Always wrap navigation targets in ",[32,473,474],{},"localePath()",[130,476,480],{"className":477,"code":478,"language":479,"meta":135,"style":135},"language-vue shiki shiki-themes github-light github-dark","\u003Ctemplate>\n  \u003CNuxtLink :to=\"localePath('\u002Fcontact')\">\n    {{ t('nav.contact') }}\n  \u003C\u002FNuxtLink>\n\u003C\u002Ftemplate>\n\n\u003Cscript setup lang=\"ts\">\nconst localePath = useLocalePath()\nconst { t } = useI18n()\n\u003C\u002Fscript>\n","vue",[32,481,482,494,513,518,527,536,540,560,577,597],{"__ignoreMap":135},[139,483,484,487,491],{"class":141,"line":142},[139,485,486],{"class":163},"\u003C",[139,488,490],{"class":489},"s9eBZ","template",[139,492,493],{"class":163},">\n",[139,495,496,499,502,505,508,511],{"class":141,"line":149},[139,497,498],{"class":163},"  \u003C",[139,500,501],{"class":489},"NuxtLink",[139,503,504],{"class":159}," :to",[139,506,507],{"class":163},"=",[139,509,510],{"class":173},"\"localePath('\u002Fcontact')\"",[139,512,493],{"class":163},[139,514,515],{"class":141,"line":167},[139,516,517],{"class":163},"    {{ t('nav.contact') }}\n",[139,519,520,523,525],{"class":141,"line":185},[139,521,522],{"class":163},"  \u003C\u002F",[139,524,501],{"class":489},[139,526,493],{"class":163},[139,528,529,532,534],{"class":141,"line":192},[139,530,531],{"class":163},"\u003C\u002F",[139,533,490],{"class":489},[139,535,493],{"class":163},[139,537,538],{"class":141,"line":198},[139,539,189],{"emptyLinePlaceholder":188},[139,541,542,544,547,550,553,555,558],{"class":141,"line":210},[139,543,486],{"class":163},[139,545,546],{"class":489},"script",[139,548,549],{"class":159}," setup",[139,551,552],{"class":159}," lang",[139,554,507],{"class":163},[139,556,557],{"class":173},"\"ts\"",[139,559,493],{"class":163},[139,561,562,565,568,571,574],{"class":141,"line":221},[139,563,564],{"class":152},"const",[139,566,567],{"class":244}," localePath",[139,569,570],{"class":152}," =",[139,572,573],{"class":159}," useLocalePath",[139,575,576],{"class":163},"()\n",[139,578,579,581,584,587,590,592,595],{"class":141,"line":232},[139,580,564],{"class":152},[139,582,583],{"class":163}," { ",[139,585,586],{"class":244},"t",[139,588,589],{"class":163}," } ",[139,591,507],{"class":152},[139,593,594],{"class":159}," useI18n",[139,596,576],{"class":163},[139,598,599,601,603],{"class":141,"line":238},[139,600,531],{"class":163},[139,602,546],{"class":489},[139,604,493],{"class":163},[36,606],{},[39,608,610,611],{"id":609},"_3-automated-multilingual-sitemap-with-xhtmllink","3. Automated Multilingual Sitemap with ",[32,612,613],{},"xhtml:link",[11,615,616,617,21],{},"For Google to rank your pages in target countries without duplicate content penalties, your sitemap must declare ",[18,618,619],{},"hreflang alternate links",[11,621,622,625,626,628],{},[32,623,624],{},"@nuxtjs\u002Fsitemap"," pairs with ",[32,627,34],{}," to generate this automatically:",[130,630,634],{"className":631,"code":632,"language":633,"meta":135,"style":135},"language-xml shiki shiki-themes github-light github-dark","\u003Curl>\n  \u003Cloc>https:\u002F\u002Fadam-portfolio.vercel.app\u002Fportfolio\u003C\u002Floc>\n  \u003Cxhtml:link rel=\"alternate\" hreflang=\"en-US\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fportfolio\" \u002F>\n  \u003Cxhtml:link rel=\"alternate\" hreflang=\"fr-FR\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Ffr\u002Fportfolio\" \u002F>\n  \u003Cxhtml:link rel=\"alternate\" hreflang=\"de-DE\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fde\u002Fportfolio\" \u002F>\n  \u003Cxhtml:link rel=\"alternate\" hreflang=\"es-ES\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fes\u002Fportfolio\" \u002F>\n  \u003Cxhtml:link rel=\"alternate\" hreflang=\"ja-JP\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fja\u002Fportfolio\" \u002F>\n\u003C\u002Furl>\n","xml",[32,635,636,641,646,651,656,661,666,671],{"__ignoreMap":135},[139,637,638],{"class":141,"line":142},[139,639,640],{},"\u003Curl>\n",[139,642,643],{"class":141,"line":149},[139,644,645],{},"  \u003Cloc>https:\u002F\u002Fadam-portfolio.vercel.app\u002Fportfolio\u003C\u002Floc>\n",[139,647,648],{"class":141,"line":167},[139,649,650],{},"  \u003Cxhtml:link rel=\"alternate\" hreflang=\"en-US\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fportfolio\" \u002F>\n",[139,652,653],{"class":141,"line":185},[139,654,655],{},"  \u003Cxhtml:link rel=\"alternate\" hreflang=\"fr-FR\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Ffr\u002Fportfolio\" \u002F>\n",[139,657,658],{"class":141,"line":192},[139,659,660],{},"  \u003Cxhtml:link rel=\"alternate\" hreflang=\"de-DE\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fde\u002Fportfolio\" \u002F>\n",[139,662,663],{"class":141,"line":198},[139,664,665],{},"  \u003Cxhtml:link rel=\"alternate\" hreflang=\"es-ES\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fes\u002Fportfolio\" \u002F>\n",[139,667,668],{"class":141,"line":210},[139,669,670],{},"  \u003Cxhtml:link rel=\"alternate\" hreflang=\"ja-JP\" href=\"https:\u002F\u002Fadam-portfolio.vercel.app\u002Fja\u002Fportfolio\" \u002F>\n",[139,672,673],{"class":141,"line":221},[139,674,675],{},"\u003C\u002Furl>\n",[36,677],{},[39,679,681],{"id":680},"_4-prerendering-the-entire-site-with-nitro","4. Prerendering the Entire Site with Nitro",[11,683,684],{},"To achieve instant delivery, configure Nitro to crawl and generate static HTML files at build time:",[130,686,688],{"className":132,"code":687,"language":134,"meta":135,"style":135},"nitro: {\n  prerender: {\n    crawlLinks: true,\n    routes: ['\u002Frobots.txt', '\u002Fsitemap.xml'],\n  },\n}\n",[32,689,690,698,705,717,735,739],{"__ignoreMap":135},[139,691,692,695],{"class":141,"line":142},[139,693,694],{"class":159},"nitro",[139,696,697],{"class":163},": {\n",[139,699,700,703],{"class":141,"line":149},[139,701,702],{"class":159},"  prerender",[139,704,697],{"class":163},[139,706,707,710,713,715],{"class":141,"line":167},[139,708,709],{"class":159},"    crawlLinks",[139,711,712],{"class":163},": ",[139,714,245],{"class":244},[139,716,207],{"class":163},[139,718,719,722,725,728,730,733],{"class":141,"line":185},[139,720,721],{"class":159},"    routes",[139,723,724],{"class":163},": [",[139,726,727],{"class":173},"'\u002Frobots.txt'",[139,729,74],{"class":163},[139,731,732],{"class":173},"'\u002Fsitemap.xml'",[139,734,182],{"class":163},[139,736,737],{"class":141,"line":192},[139,738,443],{"class":163},[139,740,741],{"class":141,"line":198},[139,742,743],{"class":163},"}\n",[11,745,746,747,750,751,754],{},"Running ",[32,748,749],{},"npm run build"," generates 100% pre-compiled HTML into ",[32,752,753],{},".vercel\u002Foutput\u002Fstatic",". The site deploys to Vercel's Edge Network with global sub-30ms response times.",[756,757,758],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}",{"title":135,"searchDepth":149,"depth":149,"links":760},[761,763,765,767],{"id":41,"depth":149,"text":762},"1. The Core Routing Strategy: prefix_except_default",{"id":454,"depth":149,"text":764},"2. Preventing Broken Links with useLocalePath()",{"id":609,"depth":149,"text":766},"3. Automated Multilingual Sitemap with xhtml:link",{"id":680,"depth":149,"text":681},"2026-09-17","Front-end developers looking for production-ready internationalization (@nuxtjs\u002Fi18n), SEO best practices, and 100 Lighthouse scores.","md",false,null,{},"\u002Fblog\u002Fen\u002Fmultilingual-nuxt4-prerendering",{"title":5,"description":769},"multilingual-nuxt4-prerendering","blog\u002Fen\u002Fmultilingual-nuxt4-prerendering",[779,780,781,479,782],"nuxt","i18n","seo","web-performance","JdyJ9rUL9fNmwOBe_yfBgLpwgVc5oFp4ccxr7QoiqRU",[785,1610],{"id":786,"title":787,"author":6,"body":788,"date":1598,"description":1599,"extension":770,"featured":771,"image":772,"meta":1600,"navigation":188,"path":1601,"readingTime":198,"seo":1602,"slug":772,"stem":1603,"tags":1604,"__hash__":1609},"blog\u002Fblog\u002Fen\u002Fapi-common-mistakes.md","6 Common API Mistakes (And How to Fix Them)",{"type":8,"value":789,"toc":1589},[790,793,795,799,810,841,861,863,867,874,954,959,1079,1081,1085,1088,1148,1151,1153,1157,1160,1293,1300,1302,1306,1309,1481,1484,1486,1490,1493,1527,1534,1536,1540,1543,1586],[11,791,792],{},"Building an API feels straightforward until your first production incident. Most bugs aren't complex — they're the same six mistakes repeated across thousands of codebases. Here's what they are and how to stop making them.",[36,794],{},[39,796,798],{"id":797},"_1-using-the-wrong-http-method","1. Using the Wrong HTTP Method",[11,800,801,802,805,806,809],{},"The most visible mistake. Using ",[32,803,804],{},"GET"," to delete a resource, or ",[32,807,808],{},"POST"," for everything because \"it works.\"",[130,811,815],{"className":812,"code":813,"language":814,"meta":135,"style":135},"language-http shiki shiki-themes github-light github-dark","# ❌ Deleting with GET — catastrophic if a browser prefetches this URL\nGET \u002Fapi\u002Fusers\u002F42\u002Fdelete\n\n# ✅ Correct\nDELETE \u002Fapi\u002Fusers\u002F42\n","http",[32,816,817,822,827,831,836],{"__ignoreMap":135},[139,818,819],{"class":141,"line":142},[139,820,821],{},"# ❌ Deleting with GET — catastrophic if a browser prefetches this URL\n",[139,823,824],{"class":141,"line":149},[139,825,826],{},"GET \u002Fapi\u002Fusers\u002F42\u002Fdelete\n",[139,828,829],{"class":141,"line":167},[139,830,189],{"emptyLinePlaceholder":188},[139,832,833],{"class":141,"line":185},[139,834,835],{},"# ✅ Correct\n",[139,837,838],{"class":141,"line":192},[139,839,840],{},"DELETE \u002Fapi\u002Fusers\u002F42\n",[11,842,843,844,846,847,849,850,51,853,856,857,860],{},"HTTP methods carry semantic meaning that clients, proxies, and caches rely on. ",[32,845,804],{}," must be idempotent and safe (no side effects). ",[32,848,808],{}," creates. ",[32,851,852],{},"PUT",[32,854,855],{},"PATCH"," update. ",[32,858,859],{},"DELETE"," removes. Violating these conventions breaks caching, browser history, and every HTTP client that follows the spec.",[36,862],{},[39,864,866],{"id":865},"_2-wrong-status-codes","2. Wrong Status Codes",[11,868,869,870,873],{},"Returning ",[32,871,872],{},"200 OK"," for an error response is the most common mistake in junior APIs.",[130,875,879],{"className":876,"code":877,"language":878,"meta":135,"style":135},"language-json shiki shiki-themes github-light github-dark","\u002F\u002F ❌ Status 200, but it's an error\n{\n  \"success\": false,\n  \"error\": \"User not found\"\n}\n\n\u002F\u002F ✅ Status 404 — the client knows immediately without parsing the body\n{\n  \"error\": \"User not found\",\n  \"code\": \"USER_NOT_FOUND\"\n}\n","json",[32,880,881,886,891,902,912,916,920,925,929,940,950],{"__ignoreMap":135},[139,882,883],{"class":141,"line":142},[139,884,885],{"class":145},"\u002F\u002F ❌ Status 200, but it's an error\n",[139,887,888],{"class":141,"line":149},[139,889,890],{"class":163},"{\n",[139,892,893,896,898,900],{"class":141,"line":167},[139,894,895],{"class":244},"  \"success\"",[139,897,712],{"class":163},[139,899,278],{"class":244},[139,901,207],{"class":163},[139,903,904,907,909],{"class":141,"line":185},[139,905,906],{"class":244},"  \"error\"",[139,908,712],{"class":163},[139,910,911],{"class":173},"\"User not found\"\n",[139,913,914],{"class":141,"line":192},[139,915,743],{"class":163},[139,917,918],{"class":141,"line":198},[139,919,189],{"emptyLinePlaceholder":188},[139,921,922],{"class":141,"line":210},[139,923,924],{"class":145},"\u002F\u002F ✅ Status 404 — the client knows immediately without parsing the body\n",[139,926,927],{"class":141,"line":221},[139,928,890],{"class":163},[139,930,931,933,935,938],{"class":141,"line":232},[139,932,906],{"class":244},[139,934,712],{"class":163},[139,936,937],{"class":173},"\"User not found\"",[139,939,207],{"class":163},[139,941,942,945,947],{"class":141,"line":238},[139,943,944],{"class":244},"  \"code\"",[139,946,712],{"class":163},[139,948,949],{"class":173},"\"USER_NOT_FOUND\"\n",[139,951,952],{"class":141,"line":250},[139,953,743],{"class":163},[11,955,956],{},[18,957,958],{},"The codes that matter most:",[960,961,962,975],"table",{},[963,964,965],"thead",{},[966,967,968,972],"tr",{},[969,970,971],"th",{},"Code",[969,973,974],{},"When to use it",[976,977,978,989,999,1009,1019,1029,1039,1049,1059,1069],"tbody",{},[966,979,980,986],{},[981,982,983],"td",{},[32,984,985],{},"200",[981,987,988],{},"Success with a body",[966,990,991,996],{},[981,992,993],{},[32,994,995],{},"201",[981,997,998],{},"Resource created (POST)",[966,1000,1001,1006],{},[981,1002,1003],{},[32,1004,1005],{},"204",[981,1007,1008],{},"Success, no body (DELETE)",[966,1010,1011,1016],{},[981,1012,1013],{},[32,1014,1015],{},"400",[981,1017,1018],{},"Invalid input from the client",[966,1020,1021,1026],{},[981,1022,1023],{},[32,1024,1025],{},"401",[981,1027,1028],{},"Not authenticated",[966,1030,1031,1036],{},[981,1032,1033],{},[32,1034,1035],{},"403",[981,1037,1038],{},"Authenticated but not authorized",[966,1040,1041,1046],{},[981,1042,1043],{},[32,1044,1045],{},"404",[981,1047,1048],{},"Resource doesn't exist",[966,1050,1051,1056],{},[981,1052,1053],{},[32,1054,1055],{},"422",[981,1057,1058],{},"Input syntactically valid but semantically wrong",[966,1060,1061,1066],{},[981,1062,1063],{},[32,1064,1065],{},"429",[981,1067,1068],{},"Rate limit exceeded",[966,1070,1071,1076],{},[981,1072,1073],{},[32,1074,1075],{},"500",[981,1077,1078],{},"Server error (never the client's fault)",[36,1080],{},[39,1082,1084],{"id":1083},"_3-trusting-client-input","3. Trusting Client Input",[11,1086,1087],{},"Every value sent by a client is a potential attack vector.",[130,1089,1093],{"className":1090,"code":1091,"language":1092,"meta":135,"style":135},"language-php shiki shiki-themes github-light github-dark","\u002F\u002F ❌ Never do this\n$id = $_GET['id'];\n$query = \"SELECT * FROM users WHERE id = $id\";\n\u002F\u002F SQL injection: ?id=1 OR 1=1\n\n\u002F\u002F ✅ Always validate and sanitize\n$id = filter_var($_GET['id'], FILTER_VALIDATE_INT);\nif (!$id) {\n    return response()->json(['error' => 'Invalid ID'], 400);\n}\n$user = User::findOrFail($id); \u002F\u002F parameterized query\n","php",[32,1094,1095,1100,1105,1110,1115,1119,1124,1129,1134,1139,1143],{"__ignoreMap":135},[139,1096,1097],{"class":141,"line":142},[139,1098,1099],{},"\u002F\u002F ❌ Never do this\n",[139,1101,1102],{"class":141,"line":149},[139,1103,1104],{},"$id = $_GET['id'];\n",[139,1106,1107],{"class":141,"line":167},[139,1108,1109],{},"$query = \"SELECT * FROM users WHERE id = $id\";\n",[139,1111,1112],{"class":141,"line":185},[139,1113,1114],{},"\u002F\u002F SQL injection: ?id=1 OR 1=1\n",[139,1116,1117],{"class":141,"line":192},[139,1118,189],{"emptyLinePlaceholder":188},[139,1120,1121],{"class":141,"line":198},[139,1122,1123],{},"\u002F\u002F ✅ Always validate and sanitize\n",[139,1125,1126],{"class":141,"line":210},[139,1127,1128],{},"$id = filter_var($_GET['id'], FILTER_VALIDATE_INT);\n",[139,1130,1131],{"class":141,"line":221},[139,1132,1133],{},"if (!$id) {\n",[139,1135,1136],{"class":141,"line":232},[139,1137,1138],{},"    return response()->json(['error' => 'Invalid ID'], 400);\n",[139,1140,1141],{"class":141,"line":238},[139,1142,743],{},[139,1144,1145],{"class":141,"line":250},[139,1146,1147],{},"$user = User::findOrFail($id); \u002F\u002F parameterized query\n",[11,1149,1150],{},"Validate: type, format, length, range. Sanitize before any database or filesystem operation. Never trust what arrives in the request body, headers, or query string.",[36,1152],{},[39,1154,1156],{"id":1155},"_4-leaking-sensitive-data","4. Leaking Sensitive Data",[11,1158,1159],{},"Returning the full database object without filtering is an invitation to a data breach.",[130,1161,1163],{"className":876,"code":1162,"language":878,"meta":135,"style":135},"\u002F\u002F ❌ Returning the raw User model\n{\n  \"id\": 42,\n  \"email\": \"user@example.com\",\n  \"password\": \"$2b$12$...\",\n  \"stripe_customer_id\": \"cus_xxx\",\n  \"internal_notes\": \"flagged for review\",\n  \"created_at\": \"2024-01-01\"\n}\n\n\u002F\u002F ✅ Return only what the client actually needs\n{\n  \"id\": 42,\n  \"email\": \"user@example.com\",\n  \"created_at\": \"2024-01-01\"\n}\n",[32,1164,1165,1170,1174,1186,1198,1210,1222,1234,1244,1248,1252,1257,1261,1271,1281,1289],{"__ignoreMap":135},[139,1166,1167],{"class":141,"line":142},[139,1168,1169],{"class":145},"\u002F\u002F ❌ Returning the raw User model\n",[139,1171,1172],{"class":141,"line":149},[139,1173,890],{"class":163},[139,1175,1176,1179,1181,1184],{"class":141,"line":167},[139,1177,1178],{"class":244},"  \"id\"",[139,1180,712],{"class":163},[139,1182,1183],{"class":244},"42",[139,1185,207],{"class":163},[139,1187,1188,1191,1193,1196],{"class":141,"line":185},[139,1189,1190],{"class":244},"  \"email\"",[139,1192,712],{"class":163},[139,1194,1195],{"class":173},"\"user@example.com\"",[139,1197,207],{"class":163},[139,1199,1200,1203,1205,1208],{"class":141,"line":192},[139,1201,1202],{"class":244},"  \"password\"",[139,1204,712],{"class":163},[139,1206,1207],{"class":173},"\"$2b$12$...\"",[139,1209,207],{"class":163},[139,1211,1212,1215,1217,1220],{"class":141,"line":198},[139,1213,1214],{"class":244},"  \"stripe_customer_id\"",[139,1216,712],{"class":163},[139,1218,1219],{"class":173},"\"cus_xxx\"",[139,1221,207],{"class":163},[139,1223,1224,1227,1229,1232],{"class":141,"line":210},[139,1225,1226],{"class":244},"  \"internal_notes\"",[139,1228,712],{"class":163},[139,1230,1231],{"class":173},"\"flagged for review\"",[139,1233,207],{"class":163},[139,1235,1236,1239,1241],{"class":141,"line":221},[139,1237,1238],{"class":244},"  \"created_at\"",[139,1240,712],{"class":163},[139,1242,1243],{"class":173},"\"2024-01-01\"\n",[139,1245,1246],{"class":141,"line":232},[139,1247,743],{"class":163},[139,1249,1250],{"class":141,"line":238},[139,1251,189],{"emptyLinePlaceholder":188},[139,1253,1254],{"class":141,"line":250},[139,1255,1256],{"class":145},"\u002F\u002F ✅ Return only what the client actually needs\n",[139,1258,1259],{"class":141,"line":261},[139,1260,890],{"class":163},[139,1262,1263,1265,1267,1269],{"class":141,"line":272},[139,1264,1178],{"class":244},[139,1266,712],{"class":163},[139,1268,1183],{"class":244},[139,1270,207],{"class":163},[139,1272,1273,1275,1277,1279],{"class":141,"line":283},[139,1274,1190],{"class":244},[139,1276,712],{"class":163},[139,1278,1195],{"class":173},[139,1280,207],{"class":163},[139,1282,1283,1285,1287],{"class":141,"line":293},[139,1284,1238],{"class":244},[139,1286,712],{"class":163},[139,1288,1243],{"class":173},[139,1290,1291],{"class":141,"line":299},[139,1292,743],{"class":163},[11,1294,1295,1296,1299],{},"Use serializers, DTOs, or API Resources (Laravel) to explicitly define what gets exposed. The rule: ",[18,1297,1298],{},"opt-in, not opt-out."," Start with nothing, add what's needed.",[36,1301],{},[39,1303,1305],{"id":1304},"_5-inconsistent-error-format","5. Inconsistent Error Format",[11,1307,1308],{},"When every endpoint returns errors differently, every client has to handle every format.",[130,1310,1312],{"className":876,"code":1311,"language":878,"meta":135,"style":135},"\u002F\u002F ❌ Endpoint A\n{ \"message\": \"Not found\" }\n\n\u002F\u002F ❌ Endpoint B\n{ \"error\": true, \"msg\": \"Validation failed\", \"fields\": [\"email\"] }\n\n\u002F\u002F ❌ Endpoint C\n\"Internal server error\"\n\n\u002F\u002F ✅ One format, everywhere\n{\n  \"error\": {\n    \"code\": \"VALIDATION_FAILED\",\n    \"message\": \"The request contains invalid fields.\",\n    \"details\": [\n      { \"field\": \"email\", \"issue\": \"Invalid email format\" }\n    ]\n  }\n}\n",[32,1313,1314,1319,1335,1339,1344,1378,1382,1387,1392,1396,1401,1405,1411,1423,1435,1443,1467,1472,1477],{"__ignoreMap":135},[139,1315,1316],{"class":141,"line":142},[139,1317,1318],{"class":145},"\u002F\u002F ❌ Endpoint A\n",[139,1320,1321,1324,1327,1329,1332],{"class":141,"line":149},[139,1322,1323],{"class":163},"{ ",[139,1325,1326],{"class":244},"\"message\"",[139,1328,712],{"class":163},[139,1330,1331],{"class":173},"\"Not found\"",[139,1333,1334],{"class":163}," }\n",[139,1336,1337],{"class":141,"line":167},[139,1338,189],{"emptyLinePlaceholder":188},[139,1340,1341],{"class":141,"line":185},[139,1342,1343],{"class":145},"\u002F\u002F ❌ Endpoint B\n",[139,1345,1346,1348,1351,1353,1355,1357,1360,1362,1365,1367,1370,1372,1375],{"class":141,"line":192},[139,1347,1323],{"class":163},[139,1349,1350],{"class":244},"\"error\"",[139,1352,712],{"class":163},[139,1354,245],{"class":244},[139,1356,74],{"class":163},[139,1358,1359],{"class":244},"\"msg\"",[139,1361,712],{"class":163},[139,1363,1364],{"class":173},"\"Validation failed\"",[139,1366,74],{"class":163},[139,1368,1369],{"class":244},"\"fields\"",[139,1371,724],{"class":163},[139,1373,1374],{"class":173},"\"email\"",[139,1376,1377],{"class":163},"] }\n",[139,1379,1380],{"class":141,"line":198},[139,1381,189],{"emptyLinePlaceholder":188},[139,1383,1384],{"class":141,"line":210},[139,1385,1386],{"class":145},"\u002F\u002F ❌ Endpoint C\n",[139,1388,1389],{"class":141,"line":221},[139,1390,1391],{"class":173},"\"Internal server error\"\n",[139,1393,1394],{"class":141,"line":232},[139,1395,189],{"emptyLinePlaceholder":188},[139,1397,1398],{"class":141,"line":238},[139,1399,1400],{"class":145},"\u002F\u002F ✅ One format, everywhere\n",[139,1402,1403],{"class":141,"line":250},[139,1404,890],{"class":163},[139,1406,1407,1409],{"class":141,"line":261},[139,1408,906],{"class":244},[139,1410,697],{"class":163},[139,1412,1413,1416,1418,1421],{"class":141,"line":272},[139,1414,1415],{"class":244},"    \"code\"",[139,1417,712],{"class":163},[139,1419,1420],{"class":173},"\"VALIDATION_FAILED\"",[139,1422,207],{"class":163},[139,1424,1425,1428,1430,1433],{"class":141,"line":283},[139,1426,1427],{"class":244},"    \"message\"",[139,1429,712],{"class":163},[139,1431,1432],{"class":173},"\"The request contains invalid fields.\"",[139,1434,207],{"class":163},[139,1436,1437,1440],{"class":141,"line":293},[139,1438,1439],{"class":244},"    \"details\"",[139,1441,1442],{"class":163},": [\n",[139,1444,1445,1448,1451,1453,1455,1457,1460,1462,1465],{"class":141,"line":299},[139,1446,1447],{"class":163},"      { ",[139,1449,1450],{"class":244},"\"field\"",[139,1452,712],{"class":163},[139,1454,1374],{"class":173},[139,1456,74],{"class":163},[139,1458,1459],{"class":244},"\"issue\"",[139,1461,712],{"class":163},[139,1463,1464],{"class":173},"\"Invalid email format\"",[139,1466,1334],{"class":163},[139,1468,1469],{"class":141,"line":305},[139,1470,1471],{"class":163},"    ]\n",[139,1473,1474],{"class":141,"line":334},[139,1475,1476],{"class":163},"  }\n",[139,1478,1479],{"class":141,"line":359},[139,1480,743],{"class":163},[11,1482,1483],{},"Define your error envelope once. Apply it everywhere via a global exception handler. Clients — including your own frontend — will thank you.",[36,1485],{},[39,1487,1489],{"id":1488},"_6-no-api-versioning","6. No API Versioning",[11,1491,1492],{},"Changing an endpoint response breaks every client using it. Without versioning, you can never evolve the API.",[130,1494,1496],{"className":812,"code":1495,"language":814,"meta":135,"style":135},"# ❌ No version — any breaking change affects all clients immediately\nGET \u002Fapi\u002Fusers\n\n# ✅ Versioned — v1 stays stable, v2 introduces breaking changes safely\nGET \u002Fapi\u002Fv1\u002Fusers\nGET \u002Fapi\u002Fv2\u002Fusers\n",[32,1497,1498,1503,1508,1512,1517,1522],{"__ignoreMap":135},[139,1499,1500],{"class":141,"line":142},[139,1501,1502],{},"# ❌ No version — any breaking change affects all clients immediately\n",[139,1504,1505],{"class":141,"line":149},[139,1506,1507],{},"GET \u002Fapi\u002Fusers\n",[139,1509,1510],{"class":141,"line":167},[139,1511,189],{"emptyLinePlaceholder":188},[139,1513,1514],{"class":141,"line":185},[139,1515,1516],{},"# ✅ Versioned — v1 stays stable, v2 introduces breaking changes safely\n",[139,1518,1519],{"class":141,"line":192},[139,1520,1521],{},"GET \u002Fapi\u002Fv1\u002Fusers\n",[139,1523,1524],{"class":141,"line":198},[139,1525,1526],{},"GET \u002Fapi\u002Fv2\u002Fusers\n",[11,1528,1529,1530,1533],{},"Version from day one, even if you only have v1. The cost of adding ",[32,1531,1532],{},"\u002Fv1\u002F"," later — after clients are in production — is much higher than the cost of including it from the start.",[36,1535],{},[39,1537,1539],{"id":1538},"the-takeaway","The Takeaway",[11,1541,1542],{},"None of these mistakes require advanced knowledge to fix. They require discipline: a checklist before every endpoint ships.",[66,1544,1547,1556,1562,1568,1574,1580],{"className":1545},[1546],"contains-task-list",[69,1548,1551,1555],{"className":1549},[1550],"task-list-item",[1552,1553],"input",{"disabled":188,"type":1554},"checkbox"," HTTP method matches the operation's semantics",[69,1557,1559,1561],{"className":1558},[1550],[1552,1560],{"disabled":188,"type":1554}," Status code is accurate",[69,1563,1565,1567],{"className":1564},[1550],[1552,1566],{"disabled":188,"type":1554}," All input is validated before use",[69,1569,1571,1573],{"className":1570},[1550],[1552,1572],{"disabled":188,"type":1554}," Response only exposes necessary fields",[69,1575,1577,1579],{"className":1576},[1550],[1552,1578],{"disabled":188,"type":1554}," Errors follow the global format",[69,1581,1583,1585],{"className":1582},[1550],[1552,1584],{"disabled":188,"type":1554}," URL includes an API version",[756,1587,1588],{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":135,"searchDepth":149,"depth":149,"links":1590},[1591,1592,1593,1594,1595,1596,1597],{"id":797,"depth":149,"text":798},{"id":865,"depth":149,"text":866},{"id":1083,"depth":149,"text":1084},{"id":1155,"depth":149,"text":1156},{"id":1304,"depth":149,"text":1305},{"id":1488,"depth":149,"text":1489},{"id":1538,"depth":149,"text":1539},"2026-06-04","From wrong HTTP methods to leaking sensitive data — the errors most developers make when building their first API, and the concrete fixes.",{},"\u002Fblog\u002Fen\u002Fapi-common-mistakes",{"title":787,"description":1599},"blog\u002Fen\u002Fapi-common-mistakes",[1605,1606,1607,1608],"api","backend","rest","best-practices","z2NMprz3c9WpXKotgDMzEF9WM_LLLolyFqidBZu4I6s",{"id":1611,"title":1612,"author":6,"body":1613,"date":2253,"description":2254,"extension":770,"featured":771,"image":772,"meta":2255,"navigation":188,"path":2256,"readingTime":198,"seo":2257,"slug":2258,"stem":2259,"tags":2260,"__hash__":2264},"blog\u002Fblog\u002Fen\u002Fapi-rate-limiting-redis.md","API Rate Limiting in Practice: Token Bucket vs. Sliding Window with Redis",{"type":8,"value":1614,"toc":2244},[1615,1618,1621,1631,1633,1637,1642,1649,1653,1656,1664,1668,1671,1673,1677,1684,2172,2174,2178,2181,2238,2241],[11,1616,1617],{},"Without API rate limiting, a single rogue script or misconfigured webhook client can fire 10,000 requests per second at your login or checkout endpoint, exhausting your database connection pool and taking your entire application down.",[11,1619,1620],{},"Rate limiting is the first line of defense against bot attacks, credential stuffing, and API resource abuse. But which algorithm should you implement?",[11,1622,1623,1624,28,1627,1630],{},"In this article, we compare the two industry-standard algorithms — ",[18,1625,1626],{},"Token Bucket",[18,1628,1629],{},"Sliding Window Log"," — and show how to implement a high-speed sliding window rate limiter in Redis.",[36,1632],{},[39,1634,1636],{"id":1635},"_1-comparing-the-algorithms","1. Comparing the Algorithms",[1638,1639,1641],"h3",{"id":1640},"a-fixed-window-counter-the-flawed-default","A. Fixed Window Counter (The Flawed Default)",[11,1643,1644,1645,1648],{},"Divides time into fixed buckets (e.g. 10:00 to 10:01). If a user can make 100 requests per minute, they can send 100 requests at 10:00:59, and another 100 requests at 10:01:01. That means ",[18,1646,1647],{},"200 requests in 2 seconds"," — double the intended burst limit!",[1638,1650,1652],{"id":1651},"b-token-bucket","B. Token Bucket",[11,1654,1655],{},"A bucket holds a fixed number of tokens (burst capacity). Tokens are continuously replenished at a constant rate. Each incoming request consumes one token.",[66,1657,1658],{},[69,1659,1660,1663],{},[18,1661,1662],{},"Great for",": APIs that want to allow legitimate temporary traffic spikes while capping sustained throughput.",[1638,1665,1667],{"id":1666},"c-sliding-window-counter-the-production-standard","C. Sliding Window Counter (The Production Standard)",[11,1669,1670],{},"Combines the low memory usage of fixed windows with the smoothness of a rolling window. It calculates the request rate by weighting the request count of the previous window and the current window.",[36,1672],{},[39,1674,1676],{"id":1675},"_2-sliding-window-rate-limiter-with-redis-sorted-sets","2. Sliding Window Rate Limiter with Redis Sorted Sets",[11,1678,1679,1680,1683],{},"Redis Sorted Sets (",[32,1681,1682],{},"ZSET",") allow us to track requests by timestamp with microsecond accuracy:",[130,1685,1687],{"className":132,"code":1686,"language":134,"meta":135,"style":135},"import Redis from 'ioredis'\n\nconst redis = new Redis(process.env.REDIS_URL!)\n\nexport async function checkRateLimit(identifier: string, limit = 60, windowInSeconds = 60) {\n  const now = Date.now()\n  const windowStart = now - (windowInSeconds * 1000)\n  const key = `ratelimit:${identifier}`\n\n  \u002F\u002F Atomic Redis Pipeline (Runs in a single round-trip)\n  const multi = redis.multi()\n  \u002F\u002F 1. Remove all request timestamps older than the active window\n  multi.zremrangebyscore(key, 0, windowStart)\n  \u002F\u002F 2. Count requests currently in the active window\n  multi.zcard(key)\n  \u002F\u002F 3. Add the current timestamp as a new request\n  multi.zadd(key, now, `${now}-${Math.random()}`)\n  \u002F\u002F 4. Set key expiration to auto-clean idle users\n  multi.expire(key, windowInSeconds)\n\n  const results = await multi.exec()\n  const currentCount = (results?.[1]?.[1] as number) || 0\n\n  if (currentCount >= limit) {\n    return {\n      allowed: false,\n      remaining: 0,\n      retryAfter: Math.ceil(windowInSeconds - ((now - windowStart) \u002F 1000))\n    }\n  }\n\n  return {\n    allowed: true,\n    remaining: limit - currentCount - 1,\n    retryAfter: 0\n  }\n}\n",[32,1688,1689,1703,1707,1734,1738,1785,1803,1829,1846,1850,1855,1872,1877,1894,1899,1909,1914,1948,1953,1963,1967,1987,2025,2029,2043,2052,2062,2072,2101,2107,2112,2117,2125,2135,2153,2162,2167],{"__ignoreMap":135},[139,1690,1691,1694,1697,1700],{"class":141,"line":142},[139,1692,1693],{"class":152},"import",[139,1695,1696],{"class":163}," Redis ",[139,1698,1699],{"class":152},"from",[139,1701,1702],{"class":173}," 'ioredis'\n",[139,1704,1705],{"class":141,"line":149},[139,1706,189],{"emptyLinePlaceholder":188},[139,1708,1709,1711,1714,1716,1719,1722,1725,1728,1731],{"class":141,"line":167},[139,1710,564],{"class":152},[139,1712,1713],{"class":244}," redis",[139,1715,570],{"class":152},[139,1717,1718],{"class":152}," new",[139,1720,1721],{"class":159}," Redis",[139,1723,1724],{"class":163},"(process.env.",[139,1726,1727],{"class":244},"REDIS_URL",[139,1729,1730],{"class":152},"!",[139,1732,1733],{"class":163},")\n",[139,1735,1736],{"class":141,"line":185},[139,1737,189],{"emptyLinePlaceholder":188},[139,1739,1740,1742,1745,1748,1751,1754,1758,1760,1763,1765,1768,1770,1773,1775,1778,1780,1782],{"class":141,"line":192},[139,1741,153],{"class":152},[139,1743,1744],{"class":152}," async",[139,1746,1747],{"class":152}," function",[139,1749,1750],{"class":159}," checkRateLimit",[139,1752,1753],{"class":163},"(",[139,1755,1757],{"class":1756},"s4XuR","identifier",[139,1759,64],{"class":152},[139,1761,1762],{"class":244}," string",[139,1764,74],{"class":163},[139,1766,1767],{"class":1756},"limit",[139,1769,570],{"class":152},[139,1771,1772],{"class":244}," 60",[139,1774,74],{"class":163},[139,1776,1777],{"class":1756},"windowInSeconds",[139,1779,570],{"class":152},[139,1781,1772],{"class":244},[139,1783,1784],{"class":163},") {\n",[139,1786,1787,1790,1793,1795,1798,1801],{"class":141,"line":198},[139,1788,1789],{"class":152},"  const",[139,1791,1792],{"class":244}," now",[139,1794,570],{"class":152},[139,1796,1797],{"class":163}," Date.",[139,1799,1800],{"class":159},"now",[139,1802,576],{"class":163},[139,1804,1805,1807,1810,1812,1815,1818,1821,1824,1827],{"class":141,"line":210},[139,1806,1789],{"class":152},[139,1808,1809],{"class":244}," windowStart",[139,1811,570],{"class":152},[139,1813,1814],{"class":163}," now ",[139,1816,1817],{"class":152},"-",[139,1819,1820],{"class":163}," (windowInSeconds ",[139,1822,1823],{"class":152},"*",[139,1825,1826],{"class":244}," 1000",[139,1828,1733],{"class":163},[139,1830,1831,1833,1836,1838,1841,1843],{"class":141,"line":221},[139,1832,1789],{"class":152},[139,1834,1835],{"class":244}," key",[139,1837,570],{"class":152},[139,1839,1840],{"class":173}," `ratelimit:${",[139,1842,1757],{"class":163},[139,1844,1845],{"class":173},"}`\n",[139,1847,1848],{"class":141,"line":232},[139,1849,189],{"emptyLinePlaceholder":188},[139,1851,1852],{"class":141,"line":238},[139,1853,1854],{"class":145},"  \u002F\u002F Atomic Redis Pipeline (Runs in a single round-trip)\n",[139,1856,1857,1859,1862,1864,1867,1870],{"class":141,"line":250},[139,1858,1789],{"class":152},[139,1860,1861],{"class":244}," multi",[139,1863,570],{"class":152},[139,1865,1866],{"class":163}," redis.",[139,1868,1869],{"class":159},"multi",[139,1871,576],{"class":163},[139,1873,1874],{"class":141,"line":261},[139,1875,1876],{"class":145},"  \u002F\u002F 1. Remove all request timestamps older than the active window\n",[139,1878,1879,1882,1885,1888,1891],{"class":141,"line":272},[139,1880,1881],{"class":163},"  multi.",[139,1883,1884],{"class":159},"zremrangebyscore",[139,1886,1887],{"class":163},"(key, ",[139,1889,1890],{"class":244},"0",[139,1892,1893],{"class":163},", windowStart)\n",[139,1895,1896],{"class":141,"line":283},[139,1897,1898],{"class":145},"  \u002F\u002F 2. Count requests currently in the active window\n",[139,1900,1901,1903,1906],{"class":141,"line":293},[139,1902,1881],{"class":163},[139,1904,1905],{"class":159},"zcard",[139,1907,1908],{"class":163},"(key)\n",[139,1910,1911],{"class":141,"line":299},[139,1912,1913],{"class":145},"  \u002F\u002F 3. Add the current timestamp as a new request\n",[139,1915,1916,1918,1921,1924,1927,1929,1932,1935,1937,1940,1943,1946],{"class":141,"line":305},[139,1917,1881],{"class":163},[139,1919,1920],{"class":159},"zadd",[139,1922,1923],{"class":163},"(key, now, ",[139,1925,1926],{"class":173},"`${",[139,1928,1800],{"class":163},[139,1930,1931],{"class":173},"}-${",[139,1933,1934],{"class":163},"Math",[139,1936,21],{"class":173},[139,1938,1939],{"class":159},"random",[139,1941,1942],{"class":173},"()",[139,1944,1945],{"class":173},"}`",[139,1947,1733],{"class":163},[139,1949,1950],{"class":141,"line":334},[139,1951,1952],{"class":145},"  \u002F\u002F 4. Set key expiration to auto-clean idle users\n",[139,1954,1955,1957,1960],{"class":141,"line":359},[139,1956,1881],{"class":163},[139,1958,1959],{"class":159},"expire",[139,1961,1962],{"class":163},"(key, windowInSeconds)\n",[139,1964,1965],{"class":141,"line":384},[139,1966,189],{"emptyLinePlaceholder":188},[139,1968,1969,1971,1974,1976,1979,1982,1985],{"class":141,"line":409},[139,1970,1789],{"class":152},[139,1972,1973],{"class":244}," results",[139,1975,570],{"class":152},[139,1977,1978],{"class":152}," await",[139,1980,1981],{"class":163}," multi.",[139,1983,1984],{"class":159},"exec",[139,1986,576],{"class":163},[139,1988,1989,1991,1994,1996,1999,2002,2005,2007,2010,2013,2016,2019,2022],{"class":141,"line":434},[139,1990,1789],{"class":152},[139,1992,1993],{"class":244}," currentCount",[139,1995,570],{"class":152},[139,1997,1998],{"class":163}," (results?.[",[139,2000,2001],{"class":244},"1",[139,2003,2004],{"class":163},"]?.[",[139,2006,2001],{"class":244},[139,2008,2009],{"class":163},"] ",[139,2011,2012],{"class":152},"as",[139,2014,2015],{"class":244}," number",[139,2017,2018],{"class":163},") ",[139,2020,2021],{"class":152},"||",[139,2023,2024],{"class":244}," 0\n",[139,2026,2027],{"class":141,"line":440},[139,2028,189],{"emptyLinePlaceholder":188},[139,2030,2031,2034,2037,2040],{"class":141,"line":446},[139,2032,2033],{"class":152},"  if",[139,2035,2036],{"class":163}," (currentCount ",[139,2038,2039],{"class":152},">=",[139,2041,2042],{"class":163}," limit) {\n",[139,2044,2046,2049],{"class":141,"line":2045},25,[139,2047,2048],{"class":152},"    return",[139,2050,2051],{"class":163}," {\n",[139,2053,2055,2058,2060],{"class":141,"line":2054},26,[139,2056,2057],{"class":163},"      allowed: ",[139,2059,278],{"class":244},[139,2061,207],{"class":163},[139,2063,2065,2068,2070],{"class":141,"line":2064},27,[139,2066,2067],{"class":163},"      remaining: ",[139,2069,1890],{"class":244},[139,2071,207],{"class":163},[139,2073,2075,2078,2081,2084,2086,2089,2091,2094,2096,2098],{"class":141,"line":2074},28,[139,2076,2077],{"class":163},"      retryAfter: Math.",[139,2079,2080],{"class":159},"ceil",[139,2082,2083],{"class":163},"(windowInSeconds ",[139,2085,1817],{"class":152},[139,2087,2088],{"class":163}," ((now ",[139,2090,1817],{"class":152},[139,2092,2093],{"class":163}," windowStart) ",[139,2095,51],{"class":152},[139,2097,1826],{"class":244},[139,2099,2100],{"class":163},"))\n",[139,2102,2104],{"class":141,"line":2103},29,[139,2105,2106],{"class":163},"    }\n",[139,2108,2110],{"class":141,"line":2109},30,[139,2111,1476],{"class":163},[139,2113,2115],{"class":141,"line":2114},31,[139,2116,189],{"emptyLinePlaceholder":188},[139,2118,2120,2123],{"class":141,"line":2119},32,[139,2121,2122],{"class":152},"  return",[139,2124,2051],{"class":163},[139,2126,2128,2131,2133],{"class":141,"line":2127},33,[139,2129,2130],{"class":163},"    allowed: ",[139,2132,245],{"class":244},[139,2134,207],{"class":163},[139,2136,2138,2141,2143,2146,2148,2151],{"class":141,"line":2137},34,[139,2139,2140],{"class":163},"    remaining: limit ",[139,2142,1817],{"class":152},[139,2144,2145],{"class":163}," currentCount ",[139,2147,1817],{"class":152},[139,2149,2150],{"class":244}," 1",[139,2152,207],{"class":163},[139,2154,2156,2159],{"class":141,"line":2155},35,[139,2157,2158],{"class":163},"    retryAfter: ",[139,2160,2161],{"class":244},"0\n",[139,2163,2165],{"class":141,"line":2164},36,[139,2166,1476],{"class":163},[139,2168,2170],{"class":141,"line":2169},37,[139,2171,743],{"class":163},[36,2173],{},[39,2175,2177],{"id":2176},"_3-returning-standard-http-rate-limit-headers","3. Returning Standard HTTP Rate Limit Headers",[11,2179,2180],{},"Whenever your server answers a request, communicate rate limit states in the response headers (following IETF draft standards):",[130,2182,2184],{"className":812,"code":2183,"language":814,"meta":135,"style":135},"HTTP\u002F1.1 429 Too Many Requests\nRetry-After: 32\nX-RateLimit-Limit: 60\nX-RateLimit-Remaining: 0\nX-RateLimit-Reset: 1773489240\nContent-Type: application\u002Fjson\n\n{\n  \"error\": \"Too Many Requests\",\n  \"message\": \"Rate limit exceeded. Please retry in 32 seconds.\"\n}\n",[32,2185,2186,2191,2196,2201,2206,2211,2216,2220,2224,2229,2234],{"__ignoreMap":135},[139,2187,2188],{"class":141,"line":142},[139,2189,2190],{},"HTTP\u002F1.1 429 Too Many Requests\n",[139,2192,2193],{"class":141,"line":149},[139,2194,2195],{},"Retry-After: 32\n",[139,2197,2198],{"class":141,"line":167},[139,2199,2200],{},"X-RateLimit-Limit: 60\n",[139,2202,2203],{"class":141,"line":185},[139,2204,2205],{},"X-RateLimit-Remaining: 0\n",[139,2207,2208],{"class":141,"line":192},[139,2209,2210],{},"X-RateLimit-Reset: 1773489240\n",[139,2212,2213],{"class":141,"line":198},[139,2214,2215],{},"Content-Type: application\u002Fjson\n",[139,2217,2218],{"class":141,"line":210},[139,2219,189],{"emptyLinePlaceholder":188},[139,2221,2222],{"class":141,"line":221},[139,2223,890],{},[139,2225,2226],{"class":141,"line":232},[139,2227,2228],{},"  \"error\": \"Too Many Requests\",\n",[139,2230,2231],{"class":141,"line":238},[139,2232,2233],{},"  \"message\": \"Rate limit exceeded. Please retry in 32 seconds.\"\n",[139,2235,2236],{"class":141,"line":250},[139,2237,743],{},[11,2239,2240],{},"This ensures honest third-party API clients and mobile SDKs can automatically back off and retry without overwhelming your infrastructure.",[756,2242,2243],{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":135,"searchDepth":149,"depth":149,"links":2245},[2246,2251,2252],{"id":1635,"depth":149,"text":1636,"children":2247},[2248,2249,2250],{"id":1640,"depth":167,"text":1641},{"id":1651,"depth":167,"text":1652},{"id":1666,"depth":167,"text":1667},{"id":1675,"depth":149,"text":1676},{"id":2176,"depth":149,"text":2177},"2026-09-14","Comparing rate-limiting algorithms to protect your backend against scrapers, credential stuffing, and bot spam with minimal latency overhead.",{},"\u002Fblog\u002Fen\u002Fapi-rate-limiting-redis",{"title":1612,"description":2254},"api-rate-limiting-redis","blog\u002Fen\u002Fapi-rate-limiting-redis",[1605,2261,2262,1606,2263],"security","redis","performance","KXTsuQOwj895dkbCDObhyO_wOncRKtB2ufJbjc-AUyc",1792236100038]