<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anup Karanjkar</title>
    <description>The latest articles on DEV Community by Anup Karanjkar (@akaranjkar08).</description>
    <link>https://dev.to/akaranjkar08</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F235395%2Fca502edd-b701-43c6-8324-7b07fefe0f24.jpg</url>
      <title>DEV Community: Anup Karanjkar</title>
      <link>https://dev.to/akaranjkar08</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akaranjkar08"/>
    <language>en</language>
    <item>
      <title>Drizzle ORM Guide: Setup, Queries and Migrations</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Sat, 05 Dec 2026 01:22:02 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/drizzle-orm-guide-setup-queries-and-migrations-57of</link>
      <guid>https://dev.to/akaranjkar08/drizzle-orm-guide-setup-queries-and-migrations-57of</guid>
      <description>&lt;p&gt;&lt;strong&gt;Drizzle ORM is a TypeScript ORM that keeps SQL visible: you declare tables in TypeScript, write queries that read like SQL, and get result types inferred from the schema.&lt;/strong&gt;[1] Choose it when you already know SQL, deploy to serverless or edge runtimes, and want migrations generated from your code. It has zero dependencies and supports PostgreSQL, MySQL, SQLite, SingleStore, MSSQL and CockroachDB.[1] One version catch up front: npm &lt;code&gt;latest&lt;/code&gt; is 0.45.4, while the current docs install &lt;code&gt;drizzle-orm@rc&lt;/code&gt; and GitHub's newest release is v1.0.0-rc.6 from November 20, 2026.[12][13][2] This guide follows the rc docs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Drizzle ORM is, and when to choose it
&lt;/h2&gt;

&lt;p&gt;Drizzle describes itself as a headless ORM: a library plus opt-in tools, not a framework you build around.[1] Two query styles ship in the same package. The SQL-like builder (&lt;code&gt;db.select().from(...)&lt;/code&gt;) mirrors SQL clause by clause. The relational API (&lt;code&gt;db.query&lt;/code&gt;) fetches nested data without hand-written joins, and Drizzle's docs say it always emits exactly one SQL query.[1] The docs call it the only ORM with both styles. That is a vendor claim, not something this guide checked.&lt;/p&gt;

&lt;p&gt;Pick it if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Your team reads SQL fluently and wants the query code to look like the SQL it produces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You deploy to serverless or edge, where a dependency-free library keeps the bundle small.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want the TypeScript schema to be the source of truth, with migration files generated from it.[7]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You are fine running on a pre-release line today (see the version section below).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Skip it if your team wants a query API that hides SQL entirely. The docs say plainly that if you know SQL you know Drizzle, which also means you need to know SQL.[1] For a refresher on the joins you will write, see &lt;a href="https://dev.to/blogs/sql-join-types-explained"&gt;SQL join types explained&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which version to install: stable 0.45.4 or the v1 rc
&lt;/h2&gt;

&lt;p&gt;The npm page lists &lt;code&gt;drizzle-orm&lt;/code&gt; 0.45.4 as the current version, published about two months before this guide's access date.[13] The GitHub releases page lists v1.0.0-rc.6, marked pre-release, published November 20, 2026.[12] The docs site's install commands use the &lt;code&gt;@rc&lt;/code&gt; tag for both packages.[2] The docs site banner still links the v1.0.0-beta.2 release, so older tutorials may mention a beta tag that is no longer the newest.&lt;/p&gt;

&lt;p&gt;That split matters because the APIs differ. The rc docs use Relational Queries v2 (&lt;code&gt;defineRelations&lt;/code&gt;). The 0.x line uses the older &lt;code&gt;relations()&lt;/code&gt; function with per-table objects. Drizzle's migration guide says RQB v1 support has been removed from the database drivers in the rc line, and that &lt;code&gt;getTableColumns&lt;/code&gt; is deprecated in v1 in favor of &lt;code&gt;getColumns&lt;/code&gt;.[6][4] Every snippet below follows the rc docs. If you pin 0.45.x, expect the relations code to differ, and check the 0.x docs before copying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Drizzle ORM setup with PostgreSQL
&lt;/h2&gt;

&lt;p&gt;Drizzle supports the &lt;code&gt;node-postgres&lt;/code&gt; and &lt;code&gt;postgres.js&lt;/code&gt; drivers natively. The docs' node-postgres install and first query look like this:[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i drizzle-orm@rc pg
npm i -D drizzle-kit@rc @types/pg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Make sure to install the 'pg' package&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;drizzle&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'drizzle-orm/node-postgres'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;drizzle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'select 1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One driver difference from the docs: &lt;code&gt;postgres.js&lt;/code&gt; uses prepared statements by default, which you may need to opt out of, for example in some AWS environments.[2] The docs list a roughly 10% speed boost from installing &lt;code&gt;pg-native&lt;/code&gt; with node-postgres.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Declare a schema in TypeScript
&lt;/h2&gt;

&lt;p&gt;A table is a TypeScript object built with the dialect's table function. This example comes from the schema docs, and the same page shows a callback form and an &lt;code&gt;import * as p&lt;/code&gt; form.[3]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;integer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pgTable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;varchar&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"drizzle-orm/pg-core"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;usersTable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;pgTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"users"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;integer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;primaryKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generatedAlwaysAsIdentity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;integer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;varchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default Drizzle uses the TypeScript key as the column name. To keep camelCase in code and snake_case in the database, either pass an alias such as &lt;code&gt;varchar('first_name')&lt;/code&gt; or use the &lt;code&gt;snakeCase.table(...)&lt;/code&gt; builder from &lt;code&gt;drizzle-orm/pg-core&lt;/code&gt;.[3] The schema can live in one file or many. If you use drizzle-kit, export every model so the migration diff can see it, and point the &lt;code&gt;schema&lt;/code&gt; option at the file, folder or glob.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Query data: SQL-like select, insert and relational queries
&lt;/h2&gt;

&lt;p&gt;The snippets below follow the docs' query examples and assume a &lt;code&gt;users&lt;/code&gt; table with a serial &lt;code&gt;id&lt;/code&gt;, a &lt;code&gt;name&lt;/code&gt; and a nullable &lt;code&gt;age&lt;/code&gt;, not the &lt;code&gt;usersTable&lt;/code&gt; from the schema example above.[4] The SQL-like API lists columns explicitly instead of using &lt;code&gt;select *&lt;/code&gt;, infers the result type from the table (including nullability) and parameterizes every value passed to filters.[4] Inserts use &lt;code&gt;.values()&lt;/code&gt; and, on PostgreSQL, &lt;code&gt;.returning()&lt;/code&gt;.[11]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'drizzle-orm'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// select with a filter&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="ow"&gt;and&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Dan'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// partial select&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;field1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// insert and get the row back&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Dan"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;returning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// upsert&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Dan'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onConflictDoUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'John'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The relational API needs relations defined once with &lt;code&gt;defineRelations&lt;/code&gt; and passed to &lt;code&gt;drizzle()&lt;/code&gt;. This is the rc docs shape (RQB v2), and it assumes a &lt;code&gt;posts&lt;/code&gt; table with an &lt;code&gt;authorId&lt;/code&gt; column in the same schema file:[5]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// relations.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;defineRelations&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"drizzle-orm"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./schema"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;defineRelations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;one&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;many&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// index.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./relations"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;drizzle&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"drizzle-orm/node-postgres"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;drizzle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Filters in the relational API are objects, not function calls. The docs list operators such as &lt;code&gt;eq&lt;/code&gt;, &lt;code&gt;gt&lt;/code&gt;, &lt;code&gt;like&lt;/code&gt;, &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;isNull&lt;/code&gt; and the combinators &lt;code&gt;OR&lt;/code&gt;, &lt;code&gt;AND&lt;/code&gt;, &lt;code&gt;NOT&lt;/code&gt; and &lt;code&gt;RAW&lt;/code&gt;. For example, &lt;code&gt;where: { id: 1 }&lt;/code&gt; filters on a column, and nested &lt;code&gt;with&lt;/code&gt; blocks can carry their own &lt;code&gt;where&lt;/code&gt;.[5]&lt;/p&gt;

&lt;h2&gt;
  
  
  drizzle-kit command reference
&lt;/h2&gt;

&lt;p&gt;drizzle-kit is the CLI companion. It supports a database-first flow (pull), a codebase-first flow with no SQL files (push), and a codebase-first flow with SQL files (generate, then migrate).[7] Dialect and schema path go in &lt;code&gt;drizzle.config.ts&lt;/code&gt; via &lt;code&gt;defineConfig&lt;/code&gt;.[8]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Options the docs list&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;drizzle-kit generate&lt;/code&gt; | Diffs the current schema against previous migrations and writes &lt;code&gt;migration.sql&lt;/code&gt; plus &lt;code&gt;snapshot.json&lt;/code&gt; in a timestamped folder[8] | &lt;code&gt;--name&lt;/code&gt;, &lt;code&gt;--custom&lt;/code&gt; (empty SQL file), &lt;code&gt;--ignore-conflicts&lt;/code&gt;, &lt;code&gt;--config&lt;/code&gt;[8] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;drizzle-kit migrate&lt;/code&gt; | Applies unapplied SQL migrations and logs them in &lt;code&gt;__drizzle_migrations&lt;/code&gt; in the &lt;code&gt;drizzle&lt;/code&gt; schema[10] | &lt;code&gt;migrations.table&lt;/code&gt; and &lt;code&gt;migrations.schema&lt;/code&gt; in config[10] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;drizzle-kit push&lt;/code&gt; | Introspects the database, diffs it against your schema and applies the changes directly, with no SQL files[9] | &lt;code&gt;--verbose&lt;/code&gt;, &lt;code&gt;--explain&lt;/code&gt; (dry run), &lt;code&gt;--force&lt;/code&gt; (auto-accept data-loss statements)[9] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;drizzle-kit pull&lt;/code&gt; | Reads an existing database and writes a TypeScript schema file[7] | See the pull docs |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;drizzle-kit export&lt;/code&gt; | Prints SQL for your schema to the console, for tools such as Atlas[7] | See the export docs |&lt;/p&gt;

&lt;p&gt;A minimal config and the generate-then-migrate loop, following the docs:[8][10]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// drizzle.config.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"drizzle-kit"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;dialect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"postgresql"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"./src/schema.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;dbCredentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"postgresql://user:password@host:port/dbname"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx drizzle-kit generate --name=init
npx drizzle-kit migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The docs describe push as the best approach for rapid prototyping and say they have seen dozens of teams and solo developers use it as their primary migrations flow in production.[9] If you want reviewable SQL in version control, use generate and migrate instead. You can also run generated migrations at application start with the &lt;code&gt;migrate()&lt;/code&gt; function from the driver's migrator module.[7]&lt;/p&gt;

&lt;h2&gt;
  
  
  Drizzle vs Prisma
&lt;/h2&gt;

&lt;p&gt;Both projects are in transition, which changes the comparison. Prisma's docs now default to Prisma ORM 8, a release candidate that &lt;code&gt;npm install prisma&lt;/code&gt; installs today. Prisma ORM 7 docs stay at /orm/v7, and Prisma says Prisma ORM 7 stays supported for 18 months after release 8.0.[14][15] The table compares the Drizzle rc docs with the Prisma ORM 8 docs, and notes where Prisma ORM 7 differs.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Drizzle ORM (rc docs)&lt;/th&gt;
&lt;th&gt;Prisma ORM 8 (rc docs)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Where the schema lives | TypeScript files using &lt;code&gt;pgTable&lt;/code&gt; and friends[3] | A contract file, &lt;code&gt;contract.prisma&lt;/code&gt;, with models; it replaces &lt;code&gt;schema.prisma&lt;/code&gt; from Prisma ORM 7[14] |&lt;/p&gt;

&lt;p&gt;| Query style | SQL-like builder, plus a relational &lt;code&gt;db.query&lt;/code&gt; API[1] | Model methods such as &lt;code&gt;db.orm.public.User.include("posts").all()&lt;/code&gt;[14] |&lt;/p&gt;

&lt;p&gt;| Result types | Inferred from the table definitions[4] | Typed from the contract after &lt;code&gt;npx prisma contract emit&lt;/code&gt;, which replaces &lt;code&gt;prisma generate&lt;/code&gt;[14] |&lt;/p&gt;

&lt;p&gt;| Migrations | &lt;code&gt;drizzle-kit generate&lt;/code&gt; then &lt;code&gt;migrate&lt;/code&gt;, or &lt;code&gt;push&lt;/code&gt;[7] | &lt;code&gt;npx prisma migration plan&lt;/code&gt; writes a migration to review; &lt;code&gt;npx prisma db migrate&lt;/code&gt; applies it[14] |&lt;/p&gt;

&lt;p&gt;| Client package | &lt;code&gt;drizzle-orm&lt;/code&gt; with a driver such as &lt;code&gt;pg&lt;/code&gt;[2] | A per-database library, &lt;code&gt;@prisma/orm-postgres&lt;/code&gt;; no &lt;code&gt;@prisma/client&lt;/code&gt;[15] |&lt;/p&gt;

&lt;p&gt;| Release state, December 5, 2026 | v1.0.0-rc.6 pre-release; npm &lt;code&gt;latest&lt;/code&gt; 0.45.4[12][13] | Release candidate; &lt;code&gt;prisma&lt;/code&gt; 8.0.0-rc.39 and &lt;code&gt;@prisma/orm-postgres&lt;/code&gt; 8.0.0-rc.28 per Prisma's page dated December 3[15] |&lt;/p&gt;

&lt;p&gt;| Databases | PostgreSQL, MySQL, SQLite, SingleStore, MSSQL, CockroachDB[1] | PostgreSQL is GA from 8.0; MongoDB, SQLite, MySQL, MariaDB are Early Access; SQL Server and CockroachDB come later[14] |&lt;/p&gt;

&lt;p&gt;Prisma's contract looks like this in its docs:[14]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// use prisma-8

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId], references: [id])
  authorId Int
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The practical difference is where you describe your data. Drizzle keeps it in TypeScript, so a table definition is also a value you can spread, share and import. Prisma keeps it in its own modeling language and gives you typed methods from it. Neither project's docs include a benchmark this guide could verify, so there are no speed claims here. Drizzle links a benchmarks page from its docs header, and anything on it is vendor-reported.&lt;/p&gt;

&lt;p&gt;If you need a stable release on a database Prisma ORM 8 does not yet cover well, Prisma's own page says to stay on Prisma ORM 7 for MySQL, MariaDB, SQL Server and CockroachDB.[14] If you are starting a PostgreSQL project and want SQL-shaped code, Drizzle on the rc tag is the closer fit. Pin the exact version either way, since Prisma notes that no compatibility between release candidates is promised.[15]&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Drizzle mistakes and what breaks
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mistake&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Installing without &lt;code&gt;@rc&lt;/code&gt; but copying rc docs | You get 0.45.4, and &lt;code&gt;defineRelations&lt;/code&gt; code may not match that line[13][6] | Install &lt;code&gt;drizzle-orm@rc&lt;/code&gt; and &lt;code&gt;drizzle-kit@rc&lt;/code&gt;, or pin 0.x and use the 0.x docs |&lt;/p&gt;

&lt;p&gt;| Not exporting a table from a schema file | drizzle-kit cannot see it in the migration diff[3] | Export every model |&lt;/p&gt;

&lt;p&gt;| Forgetting &lt;code&gt;{ relations }&lt;/code&gt; in &lt;code&gt;drizzle()&lt;/code&gt; | &lt;code&gt;db.query&lt;/code&gt; has nothing to resolve[5] | Pass the relations object at initialization |&lt;/p&gt;

&lt;p&gt;| Referencing the imported table inside relational &lt;code&gt;orderBy&lt;/code&gt;, &lt;code&gt;where.RAW&lt;/code&gt; or &lt;code&gt;extras&lt;/code&gt; | Docs mark it as wrong; the callback parameter supplies the aliased table for correct SQL[5] | Use the callback: &lt;code&gt;orderBy: (t) =&amp;gt; ...&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Writing &lt;code&gt;sql&amp;lt;number&amp;gt;&lt;/code&gt; for a value the driver returns as a string | Types and runtime values disagree; Drizzle cannot cast from the generic[4] | Match the generic to the real type or use &lt;code&gt;.mapWith()&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Running &lt;code&gt;push --force&lt;/code&gt; against production | Data-loss statements are accepted automatically[9] | Run &lt;code&gt;push --explain&lt;/code&gt; first, or switch to generate and migrate |&lt;/p&gt;

&lt;p&gt;| Relying on a driver's custom type parsers after rc.6 | The rc.6 notes say drivers no longer configure output decoding, and custom parsers need custom codecs[12] | Read the rc.6 release notes before upgrading |&lt;/p&gt;

&lt;p&gt;A last habit worth keeping: read the generated &lt;code&gt;migration.sql&lt;/code&gt; before it runs. When you want to inspect or tidy hand-written SQL for a custom migration, the &lt;a href="https://dev.to/tools/sql-formatter"&gt;SQL formatter&lt;/a&gt; helps. If a column is a timestamp, decide on time zone handling at schema time. The &lt;a href="https://dev.to/blogs/postgres-timestamp-vs-timestamptz-rule-bugs-migration-2026"&gt;PostgreSQL timestamp vs timestamptz guide&lt;/a&gt; covers the rule and the bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/overview" rel="noopener noreferrer"&gt;Why Drizzle?, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/get-started-postgresql" rel="noopener noreferrer"&gt;Drizzle &amp;lt;&amp;gt; PostgreSQL, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/sql-schema-declaration" rel="noopener noreferrer"&gt;Drizzle schema, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/select" rel="noopener noreferrer"&gt;SQL Select, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/rqb" rel="noopener noreferrer"&gt;Drizzle Queries (relational queries), Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/relations-v1-v2" rel="noopener noreferrer"&gt;Migrating to Relational Queries version 2, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/migrations" rel="noopener noreferrer"&gt;Drizzle migrations fundamentals, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/drizzle-kit-generate" rel="noopener noreferrer"&gt;drizzle-kit generate, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/drizzle-kit-push" rel="noopener noreferrer"&gt;drizzle-kit push, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/drizzle-kit-migrate" rel="noopener noreferrer"&gt;drizzle-kit migrate, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://orm.drizzle.team/docs/insert" rel="noopener noreferrer"&gt;SQL Insert, Drizzle ORM documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/drizzle-team/drizzle-orm/releases" rel="noopener noreferrer"&gt;Releases, drizzle-team/drizzle-orm, GitHub (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.npmjs.com/package/drizzle-orm" rel="noopener noreferrer"&gt;drizzle-orm, npm (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.prisma.io/docs/orm" rel="noopener noreferrer"&gt;What is Prisma ORM?, Prisma Documentation (accessed December 5, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  15. &lt;a href="https://www.prisma.io/docs/orm/release-status" rel="noopener noreferrer"&gt;Prisma ORM release status, Prisma Documentation (accessed December 5, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/drizzle-orm-getting-started-guide" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>drizzleorm</category>
      <category>drizzlevs</category>
      <category>drizzlekitmigrations</category>
    </item>
    <item>
      <title>Git Diff Explained: Flags, Output, Common Uses</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Fri, 04 Dec 2026 01:26:59 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/git-diff-explained-flags-output-common-uses-7b7</link>
      <guid>https://dev.to/akaranjkar08/git-diff-explained-flags-output-common-uses-7b7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Git diff shows changes, and which changes depends on the arguments. With no arguments it compares your working tree to the index, so it shows edits you have made but not yet staged. &lt;code&gt;git diff --cached&lt;/code&gt; (or &lt;code&gt;--staged&lt;/code&gt;) flips that: it compares the index to the last commit, which is what a plain &lt;code&gt;git commit&lt;/code&gt; would record.&lt;/strong&gt;[1] Add a commit name and the working tree is compared to that commit instead. Name two commits and you compare those two. Below: the comparison forms in a table, how to read the patch output, the flags that matter, edge cases around renames, binaries and merges, and the mistakes that waste the most time. To compare two pasted snippets with no repository at all, the &lt;a href="https://dev.to/tools/diff-checker"&gt;diff checker&lt;/a&gt; does it in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  What git diff does
&lt;/h2&gt;

&lt;p&gt;The official description is broad: show changes between the working tree and the index or a tree, between the index and a tree, between two trees, from a merge, between two blob objects, or between two files on disk.[1] Every one of those is the same operation. Git picks two endpoints, compares them, and prints what differs.&lt;/p&gt;

&lt;p&gt;Three places hold your content, and the whole command makes sense once you hold them in mind. The working tree is the files on disk. The index (the staging area) is what the next commit will contain. HEAD is the last commit. Each form of &lt;code&gt;git diff&lt;/code&gt; is a pair chosen from those, or from other commits you name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Staged versus unstaged: the four everyday forms
&lt;/h2&gt;

&lt;p&gt;The docs list four ways to check your working tree, and they cover most daily use.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff            &lt;span class="c"&gt;# (1) working tree vs index: not yet staged&lt;/span&gt;
git diff --cached   &lt;span class="c"&gt;# (2) index vs last commit: what git commit would record&lt;/span&gt;
git diff HEAD       &lt;span class="c"&gt;# (3) working tree vs last commit: what commit -a would record&lt;/span&gt;
git diff AUTO_MERGE &lt;span class="c"&gt;# (4) working tree vs the auto-merge result, during conflicts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Form 1 is "changes in the working tree not yet staged for the next commit." Form 2 is "what you would be committing if you run &lt;code&gt;git commit&lt;/code&gt; without &lt;code&gt;-a&lt;/code&gt; option." Form 3 is "what you would be committing if you run &lt;code&gt;git commit -a&lt;/code&gt;."[1] Form 4 uses the &lt;code&gt;AUTO_MERGE&lt;/code&gt; ref, which the &lt;code&gt;ort&lt;/code&gt; merge strategy writes when it hits conflicts. Comparing against it shows the changes you have made so far to resolve textual conflicts.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison forms at a glance
&lt;/h2&gt;

&lt;p&gt;The classic confusion: stage a file with &lt;code&gt;git add&lt;/code&gt;, run plain &lt;code&gt;git diff&lt;/code&gt;, and the output is empty, because the change moved to the &lt;code&gt;--cached&lt;/code&gt; view.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Compares&lt;/th&gt;
&lt;th&gt;Use it for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;git diff&lt;/code&gt; | Working tree vs index[1] | Review edits before staging |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;git diff --cached&lt;/code&gt; | Index vs &lt;code&gt;HEAD&lt;/code&gt;; &lt;code&gt;--staged&lt;/code&gt; is a synonym[1] | Review exactly what you are about to commit |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;git diff HEAD&lt;/code&gt; | Working tree vs latest commit[1] | See staged and unstaged together |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;git diff &amp;lt;commit&amp;gt;&lt;/code&gt; | Working tree vs the named commit; a branch name compares with that branch's tip[1] | How far your files have drifted from another branch |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;git diff A B&lt;/code&gt; | Two arbitrary commits[1] | Compare two tags, releases or branch tips |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;git diff A...B&lt;/code&gt; | Equivalent to &lt;code&gt;git diff $(git merge-base A B) B&lt;/code&gt;[1] | What a branch added since it split off |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;git diff --no-index a b&lt;/code&gt; | Two paths on the filesystem; implies &lt;code&gt;--exit-code&lt;/code&gt;[1] | Diff files that are not tracked by Git |&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparing commits and branches
&lt;/h2&gt;

&lt;p&gt;The docs give a compact set of examples for comparing against arbitrary commits and between branches.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff &lt;span class="nb"&gt;test&lt;/span&gt;             &lt;span class="c"&gt;# working tree vs the tip of branch "test"&lt;/span&gt;
git diff HEAD -- ./test   &lt;span class="c"&gt;# working tree vs HEAD, limited to the file "test"&lt;/span&gt;
git diff HEAD^ HEAD       &lt;span class="c"&gt;# the version before the last commit vs the last commit&lt;/span&gt;

git diff topic master     &lt;span class="c"&gt;# changes between the two branch tips&lt;/span&gt;
git diff topic..master    &lt;span class="c"&gt;# same as above&lt;/span&gt;
git diff topic...master   &lt;span class="c"&gt;# changes on master since topic was started off it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the part that trips people up. The two-dot and three-dot spellings in &lt;code&gt;git diff&lt;/code&gt; do not mean what they mean in &lt;code&gt;git log&lt;/code&gt;. The docs spell it out: &lt;code&gt;diff&lt;/code&gt; is about comparing two endpoints, not ranges, and the range notations do not mean a range as defined in the "SPECIFYING RANGES" section of gitrevisions.[1] Two dots is just "diff these two tips." Three dots starts from the common ancestor, which makes it the right choice for "what did this feature branch change," because it ignores whatever landed on the other branch in the meantime.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the patch output
&lt;/h2&gt;

&lt;p&gt;The default output is patch text. &lt;code&gt;-p&lt;/code&gt;, &lt;code&gt;-u&lt;/code&gt; and &lt;code&gt;--patch&lt;/code&gt; all request it, and it is the default.[1] Each changed file starts with a header that differs slightly from a traditional diff.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;diff --git a/file1 b/file2
old mode 
new mode 
deleted file mode 
new file mode 
copy from 

copy to 
rename from 
rename to 
similarity index 
dissimilarity index 
index .. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That block is the header form from the docs, not output from a real run: the first line is always present, and one or more of the extended lines follow it depending on what happened to the file.[1] Reading it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;a/&lt;/code&gt; and &lt;code&gt;b/&lt;/code&gt; names are the same unless a rename or copy is involved. Even for a creation or deletion, &lt;code&gt;/dev/null&lt;/code&gt; is not used in place of them.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;File modes print as 6-digit octal numbers that include the file type and permission bits. The mode appears on the &lt;code&gt;index&lt;/code&gt; line only when it does not change; otherwise separate &lt;code&gt;old mode&lt;/code&gt; and &lt;code&gt;new mode&lt;/code&gt; lines show it.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The similarity index is the percentage of unchanged lines, and the dissimilarity index is the percentage of changed lines, both rounded down. A similarity of 100% is reserved for two equal files.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lines in the hunk body start with &lt;code&gt;+&lt;/code&gt; for new, &lt;code&gt;-&lt;/code&gt; for old and a space for context.[1] Hunk headers also name the function the hunk applies to, and how that name is found can be customized per language through gitattributes.[1]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The flags worth knowing
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Flag&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;--stat&lt;/code&gt; | A diffstat. Width defaults to terminal width, or 80 columns when not connected to a terminal[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--numstat&lt;/code&gt; | Added and deleted counts in decimal with full pathnames, for scripts. Binary files print two &lt;code&gt;-&lt;/code&gt; instead of &lt;code&gt;0 0&lt;/code&gt;[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--name-only&lt;/code&gt; | Only the name of each changed file in the post-image tree[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--name-status&lt;/code&gt; | Name plus a status letter for each changed file[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;-U&amp;lt;n&amp;gt;&lt;/code&gt; | Use &lt;code&gt;n&lt;/code&gt; lines of context. Defaults to &lt;code&gt;diff.context&lt;/code&gt; or 3[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;-w&lt;/code&gt; | Ignore whitespace when comparing lines, even if one line has whitespace where the other has none[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--word-diff&lt;/code&gt; | Word-level changes inside each hunk; mode defaults to &lt;code&gt;plain&lt;/code&gt;[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--color-moved&lt;/code&gt; | Color moved lines differently; defaults to &lt;code&gt;zebra&lt;/code&gt; when given with no mode[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--diff-filter=&lt;/code&gt; | Keep only files by status: &lt;code&gt;A&lt;/code&gt;dded, &lt;code&gt;C&lt;/code&gt;opied, &lt;code&gt;D&lt;/code&gt;eleted, &lt;code&gt;M&lt;/code&gt;odified, &lt;code&gt;R&lt;/code&gt;enamed, &lt;code&gt;T&lt;/code&gt;ype changed, &lt;code&gt;U&lt;/code&gt;nmerged. Lowercase letters exclude[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;-M&lt;/code&gt; / &lt;code&gt;-C&lt;/code&gt; | Detect renames, or copies as well[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;-S&amp;lt;string&amp;gt;&lt;/code&gt; / &lt;code&gt;-G&amp;lt;regex&amp;gt;&lt;/code&gt; | Find changes that alter the count of a string, or whose added or removed lines match a regex[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;-R&lt;/code&gt; | Swap the two inputs, so the diff runs in reverse[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--check&lt;/code&gt; | Warn about conflict markers or whitespace errors; exits non-zero if found[1] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;--exit-code&lt;/code&gt; / &lt;code&gt;--quiet&lt;/code&gt; | Exit 1 when there are differences, 0 when none. &lt;code&gt;--quiet&lt;/code&gt; also suppresses all output[1] |&lt;/p&gt;

&lt;h2&gt;
  
  
  Limiting the output
&lt;/h2&gt;

&lt;p&gt;A big diff is rarely useful as raw patch text. The docs show three ways to cut it down: &lt;code&gt;git diff --diff-filter=MRC&lt;/code&gt; (modification, rename and copy, no add or delete), &lt;code&gt;git diff --name-status&lt;/code&gt; (names and the nature of change, no diff body) and &lt;code&gt;git diff arch/i386 include/asm-i386&lt;/code&gt; (limit output to named subtrees).[1] A directory name after the options gives every file under it, and &lt;code&gt;--relative&lt;/code&gt; excludes changes outside the directory you are in.[1] The status letters are A (addition), C (copy), D (deletion), M (modification of contents or mode), R (rename), T (type change), U (unmerged) and X (unknown, which the docs call "most probably a bug").[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Whitespace noise and word-level diffs
&lt;/h2&gt;

&lt;p&gt;A reformat that touches every line buries the real change, and the whitespace flags hide it.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff -w                        &lt;span class="c"&gt;# ignore all whitespace when comparing lines&lt;/span&gt;
git diff -b                        &lt;span class="c"&gt;# ignore changes in the amount of whitespace&lt;/span&gt;
git diff --ignore-space-at-eol     &lt;span class="c"&gt;# ignore trailing whitespace changes only&lt;/span&gt;
git diff --word-diff               &lt;span class="c"&gt;# [-removed-] and {added} inline&lt;/span&gt;
git diff --word-diff=color         &lt;span class="c"&gt;# color only, no delimiters&lt;/span&gt;
git diff --word-diff-regex=.       &lt;span class="c"&gt;# character-by-character differences&lt;/span&gt;
git diff --check                   &lt;span class="c"&gt;# flag whitespace errors and conflict markers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Plain word diff shows words as &lt;code&gt;[-removed-]&lt;/code&gt; and &lt;code&gt;{added}&lt;/code&gt;, and the docs warn that it makes no attempt to escape the delimiters if they appear in the input, "so the output may be ambiguous."[1] By default a word is a run of non-whitespace, and &lt;code&gt;--word-diff-regex=.&lt;/code&gt; treats each character as a word. The docs also caution that &lt;code&gt;--word-diff&lt;/code&gt; works by taking the same line-by-line diff and computing word changes inside each hunk, so it can produce a larger diff than a dedicated word-diff tool.[1]&lt;/p&gt;

&lt;p&gt;For whitespace hygiene before a commit, &lt;code&gt;--check&lt;/code&gt; is the better tool than eyeballing. By default it treats trailing whitespace, including lines that are only whitespace, and a space immediately followed by a tab inside the initial indent as errors; &lt;code&gt;core.whitespace&lt;/code&gt; changes that.[1] When a whitespace-only diff is the question, pasting both versions into the &lt;a href="https://dev.to/tools/diff-checker"&gt;diff checker&lt;/a&gt; shows the result without touching your repository state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using git diff in scripts and CI
&lt;/h2&gt;

&lt;p&gt;Exit status is the interface for automation. &lt;code&gt;--exit-code&lt;/code&gt; makes the command exit with codes similar to &lt;code&gt;diff&lt;/code&gt;(1): 1 if there were differences and 0 for none. &lt;code&gt;--quiet&lt;/code&gt; disables all output and implies &lt;code&gt;--exit-code&lt;/code&gt;.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# fail a script step if tracked files have unstaged changes&lt;/span&gt;
git diff --quiet &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"working tree has unstaged changes"&lt;/span&gt;

&lt;span class="c"&gt;# fail if the index differs from HEAD&lt;/span&gt;
git diff --cached --quiet &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"staged changes present"&lt;/span&gt;

&lt;span class="c"&gt;# machine-readable per-file counts (tab separated: added, deleted, path)&lt;/span&gt;
git diff --numstat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One caveat: &lt;code&gt;--check&lt;/code&gt; exits non-zero on problems but documented as not compatible with &lt;code&gt;--exit-code&lt;/code&gt;, so use one or the other per command.[1] For &lt;code&gt;--numstat&lt;/code&gt; or &lt;code&gt;--name-only&lt;/code&gt; output a script will parse, add &lt;code&gt;-z&lt;/code&gt;, which uses NULs as terminators and stops pathnames being quoted per &lt;code&gt;core.quotePath&lt;/code&gt;.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Edge cases
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Renames and copies.&lt;/strong&gt; Rename detection is on by default for the porcelain &lt;code&gt;git diff&lt;/code&gt;: &lt;code&gt;diff.renames&lt;/code&gt; defaults to &lt;code&gt;true&lt;/code&gt;, and setting it to &lt;code&gt;copies&lt;/code&gt; also detects copies.[1] The similarity threshold defaults to 50%, and &lt;code&gt;-M100%&lt;/code&gt; limits detection to exact renames.[1] The exhaustive fallback is O(N^2), so it is skipped past a file-count limit: &lt;code&gt;-l&lt;/code&gt; defaults to &lt;code&gt;diff.renameLimit&lt;/code&gt;, which is currently 1000 when unset.[1] A huge refactor may therefore show as separate deletes and adds. &lt;code&gt;--no-renames&lt;/code&gt; turns detection off entirely.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Binary files.&lt;/strong&gt; &lt;code&gt;--numstat&lt;/code&gt; prints two &lt;code&gt;-&lt;/code&gt; for them, and &lt;code&gt;-G&lt;/code&gt; ignores binary patches unless &lt;code&gt;--text&lt;/code&gt; is supplied. &lt;code&gt;--binary&lt;/code&gt; outputs a binary diff that &lt;code&gt;git apply&lt;/code&gt; can apply.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Merge conflicts.&lt;/strong&gt; During a conflict, &lt;code&gt;-1&lt;/code&gt; (&lt;code&gt;--base&lt;/code&gt;), &lt;code&gt;-2&lt;/code&gt; (&lt;code&gt;--ours&lt;/code&gt;) and &lt;code&gt;-3&lt;/code&gt; (&lt;code&gt;--theirs&lt;/code&gt;) compare the working tree against stage 1, 2 or 3 of the index, which exists only for unmerged entries. &lt;code&gt;-0&lt;/code&gt; omits diff output for unmerged entries and just prints "Unmerged".[1] For a merge commit itself, &lt;code&gt;git diff A A^@&lt;/code&gt;, &lt;code&gt;git diff A^!&lt;/code&gt; and &lt;code&gt;git show A&lt;/code&gt; all give the same combined diff.[1] Combined diffs use &lt;code&gt;diff --cc&lt;/code&gt; or &lt;code&gt;diff --combined&lt;/code&gt; headers and one column per parent. Their chunk headers carry one more &lt;code&gt;@&lt;/code&gt; than the number of parents, which keeps people from feeding them to &lt;code&gt;patch -p1&lt;/code&gt; by accident.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The diff algorithm.&lt;/strong&gt; The default is &lt;code&gt;myers&lt;/code&gt;, "the basic greedy diff algorithm." &lt;code&gt;patience&lt;/code&gt;, &lt;code&gt;histogram&lt;/code&gt; and &lt;code&gt;minimal&lt;/code&gt; are alternatives, chosen with &lt;code&gt;--diff-algorithm=&lt;/code&gt; or &lt;code&gt;diff.algorithm&lt;/code&gt;. To return to the default after configuring another, pass &lt;code&gt;--diff-algorithm=default&lt;/code&gt;.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Config that changes what you see
&lt;/h2&gt;

&lt;p&gt;When two machines print different diffs for the same change, check configuration. &lt;code&gt;diff.context&lt;/code&gt; replaces the default of 3 context lines (and &lt;code&gt;-U&lt;/code&gt; overrides it), &lt;code&gt;diff.algorithm&lt;/code&gt; picks the algorithm, &lt;code&gt;diff.colorMoved&lt;/code&gt; colors moved lines, &lt;code&gt;diff.renames&lt;/code&gt; takes &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;true&lt;/code&gt; (the default) or &lt;code&gt;copies&lt;/code&gt;, and &lt;code&gt;diff.mnemonicPrefix&lt;/code&gt; swaps the &lt;code&gt;a/&lt;/code&gt; and &lt;code&gt;b/&lt;/code&gt; prefixes.[1] Several have command-line counterparts that override them: &lt;code&gt;--no-color-moved&lt;/code&gt;, &lt;code&gt;--no-relative&lt;/code&gt;, &lt;code&gt;--no-renames&lt;/code&gt; and &lt;code&gt;--default-prefix&lt;/code&gt;.[1] Run once with the overrides before blaming the repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Running plain git diff after git add and reading the empty output as "no changes."&lt;/strong&gt; The change is in the index. Use &lt;code&gt;git diff --cached&lt;/code&gt;, or &lt;code&gt;git diff HEAD&lt;/code&gt; to see staged and unstaged together.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expecting a brand-new file to appear.&lt;/strong&gt; The default form compares the working tree with the index, and a file that was never added is not in the index. Check &lt;code&gt;git status&lt;/code&gt; first. Entries added with &lt;code&gt;git add -N&lt;/code&gt; do show up, as an empty existing file in &lt;code&gt;git diff&lt;/code&gt;.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using three dots when two were meant.&lt;/strong&gt; &lt;code&gt;A..B&lt;/code&gt; compares the two tips; &lt;code&gt;A...B&lt;/code&gt; starts from their common ancestor.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Passing both &lt;code&gt;--check&lt;/code&gt; and &lt;code&gt;--exit-code&lt;/code&gt;.&lt;/strong&gt; The docs say they are not compatible.[1] Pick the one that matches the question: "are there whitespace errors" or "are there any differences."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applying a diff made with options that make it unappliable.&lt;/strong&gt; &lt;code&gt;-D&lt;/code&gt; omits the preimage of deletes, and the docs say the result is not meant to be applied with &lt;code&gt;patch&lt;/code&gt; or &lt;code&gt;git apply&lt;/code&gt;.[1] Textconv output and combined-diff output are also for reading only.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trusting &lt;code&gt;-w&lt;/code&gt; to prove a change is safe.&lt;/strong&gt; It ignores differences even where one line has whitespace and the other has none,[1] so a change that only adds or removes whitespace is invisible with it. Rerun without &lt;code&gt;-w&lt;/code&gt; before approving.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which form to reach for
&lt;/h2&gt;

&lt;p&gt;Before committing, run &lt;code&gt;git diff&lt;/code&gt; for what is unstaged, then &lt;code&gt;git diff --cached&lt;/code&gt; for what will be recorded. Before opening a pull request, run &lt;code&gt;git diff main...HEAD&lt;/code&gt; in the three-dot form to see only your branch's work, and add &lt;code&gt;--stat&lt;/code&gt; for a size check. In a script, use &lt;code&gt;--quiet&lt;/code&gt; and read the exit code. For rewritten files, add &lt;code&gt;-w&lt;/code&gt; or &lt;code&gt;--word-diff&lt;/code&gt; to find the real change, then drop the flag to confirm. For a text pair that never lived in Git, use the browser diff checker above. For the commands that act on what a diff shows, such as rebasing and cherry-picking, see the guide to &lt;a href="https://dev.to/blogs/git-advanced-commands-rebase-cherry-pick-bisect-2026"&gt;advanced Git commands&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1. &lt;a href="https://git-scm.com/docs/git-diff" rel="noopener noreferrer"&gt;git-diff, Git documentation (accessed December 4, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/git-diff-explained" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>gitdiff</category>
    </item>
    <item>
      <title>SQL Join Types: INNER, LEFT, RIGHT, FULL, CROSS</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Thu, 03 Dec 2026 01:21:29 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/sql-join-types-inner-left-right-full-cross-3i6k</link>
      <guid>https://dev.to/akaranjkar08/sql-join-types-inner-left-right-full-cross-3i6k</guid>
      <description>&lt;p&gt;&lt;strong&gt;SQL join types come down to five choices. INNER JOIN returns only rows that match on both sides. LEFT JOIN keeps every row from the left table and fills the right side with NULL when nothing matches. RIGHT JOIN does the same for the right table. FULL JOIN keeps unmatched rows from both. CROSS JOIN returns every pairing.&lt;/strong&gt;[1] The verdict: write INNER when you want matches only, LEFT when the left table is the list you must not lose, and reach for FULL or CROSS only on purpose. MySQL's manual recommends LEFT over RIGHT for portability.[2] Below: the PostgreSQL docs example with exact outputs, a reference table, the ON versus WHERE trap and the mistakes that cost the most time. To tidy a long join before you read it, paste it into the &lt;a href="https://dev.to/tools/sql-formatter"&gt;SQL formatter&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a join does
&lt;/h2&gt;

&lt;p&gt;A joined table is derived from two other tables according to the rules of the join type. The general shape is &lt;code&gt;T1 join_type T2 [ join_condition ]&lt;/code&gt;, and joins can be chained or nested. Without parentheses, PostgreSQL nests &lt;code&gt;JOIN&lt;/code&gt; clauses left to right.[1] SQLite describes the same model from the other end: every join starts from the Cartesian product of the left and right datasets, and the join condition then decides which combined rows survive.[3]&lt;/p&gt;

&lt;p&gt;That mental model explains most surprises. Inner and outer joins differ only in what happens to rows the condition rejects.&lt;/p&gt;

&lt;h2&gt;
  
  
  The join types and what each returns
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Join type&lt;/th&gt;
&lt;th&gt;Rows returned&lt;/th&gt;
&lt;th&gt;Unmatched rows&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;INNER JOIN&lt;/code&gt; | One row for each pair that satisfies the join condition[1] | Dropped from both sides |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;LEFT [OUTER] JOIN&lt;/code&gt; | Inner join first, then each left row with no match is added with NULLs in the right table's columns. At least one row per left row[1] | Left kept, right dropped |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;RIGHT [OUTER] JOIN&lt;/code&gt; | The converse: at least one row per right row, NULLs in the left table's columns[1] | Right kept, left dropped |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;FULL [OUTER] JOIN&lt;/code&gt; | Inner join, plus unmatched left rows padded with NULLs, plus unmatched right rows padded with NULLs[1] | Both kept |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;CROSS JOIN&lt;/code&gt; | Every combination of rows. With N and M rows you get N * M rows[1] | No condition, so nothing is unmatched |&lt;/p&gt;

&lt;p&gt;The words &lt;code&gt;INNER&lt;/code&gt; and &lt;code&gt;OUTER&lt;/code&gt; are optional in PostgreSQL, and &lt;code&gt;INNER&lt;/code&gt; is the default. &lt;code&gt;LEFT&lt;/code&gt;, &lt;code&gt;RIGHT&lt;/code&gt; and &lt;code&gt;FULL&lt;/code&gt; imply an outer join.[1] So &lt;code&gt;JOIN&lt;/code&gt; alone means an inner join and &lt;code&gt;LEFT JOIN&lt;/code&gt; means &lt;code&gt;LEFT OUTER JOIN&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worked example: the PostgreSQL docs tables
&lt;/h2&gt;

&lt;p&gt;The PostgreSQL documentation uses two small tables, and its outputs are the clearest reference there is. They are reproduced here as printed in the docs.[1] Table &lt;code&gt;t1&lt;/code&gt; holds rows 1/a, 2/b, 3/c. Table &lt;code&gt;t2&lt;/code&gt; holds rows 1/xxx, 3/yyy, 5/zzz. The key &lt;code&gt;num&lt;/code&gt; exists in both, and the values 2 and 5 each have no partner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- t1: (num, name)   1 a | 2 b | 3 c&lt;/span&gt;
&lt;span class="c1"&gt;-- t2: (num, value)  1 xxx | 3 yyy | 5 zzz&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c1"&gt;-----+------+-----+-------&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;xxx&lt;/span&gt;
   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;yyy&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c1"&gt;-----+------+-----+-------&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;xxx&lt;/span&gt;
   &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;
   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;yyy&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c1"&gt;-----+------+-----+-------&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;xxx&lt;/span&gt;
   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;yyy&lt;/span&gt;
     &lt;span class="o"&gt;|&lt;/span&gt;      &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;zzz&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;FULL&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c1"&gt;-----+------+-----+-------&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;xxx&lt;/span&gt;
   &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;
   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;yyy&lt;/span&gt;
     &lt;span class="o"&gt;|&lt;/span&gt;      &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;zzz&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="k"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the row counts, not just the rows. Inner returns 2, left returns 3 because row 2/b survives, right returns 3 because row 5/zzz survives, and full returns 4 because both survive. The docs also show &lt;code&gt;t1 CROSS JOIN t2&lt;/code&gt; returning 9 rows, which is 3 times 3.[1]&lt;/p&gt;

&lt;p&gt;The docs state two equivalences worth memorizing. &lt;code&gt;FROM T1 CROSS JOIN T2&lt;/code&gt; is the same as &lt;code&gt;FROM T1 INNER JOIN T2 ON TRUE&lt;/code&gt;, and also the same as &lt;code&gt;FROM T1, T2&lt;/code&gt;.[1] Note the duplicate &lt;code&gt;num&lt;/code&gt; column in the &lt;code&gt;ON&lt;/code&gt; outputs above. The next section removes it.&lt;/p&gt;

&lt;h2&gt;
  
  
  ON, USING and NATURAL
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ON&lt;/code&gt; is the general form: any Boolean expression of the kind you would put in &lt;code&gt;WHERE&lt;/code&gt;. A pair of rows matches when it evaluates to true.[1] &lt;code&gt;USING&lt;/code&gt; is shorthand for the case where both tables name the join column the same way. &lt;code&gt;USING (a, b)&lt;/code&gt; produces the condition &lt;code&gt;ON T1.a = T2.a AND T1.b = T2.b&lt;/code&gt;, and it prints each listed column once.[1] With &lt;code&gt;t1&lt;/code&gt; and &lt;code&gt;t2&lt;/code&gt; above, &lt;code&gt;INNER JOIN t2 USING (num)&lt;/code&gt; returns the columns num, name, value, so the duplicate &lt;code&gt;num&lt;/code&gt; disappears.[1]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NATURAL&lt;/code&gt; goes one step further and builds the &lt;code&gt;USING&lt;/code&gt; list for you from every column name that appears in both tables.[1] That convenience is the risk. PostgreSQL's docs call &lt;code&gt;USING&lt;/code&gt; reasonably safe from column changes in the joined relations, and &lt;code&gt;NATURAL&lt;/code&gt; "considerably more risky", because a schema change that adds a new matching column name makes the join combine that column too.[1] If two tables share no column names, &lt;code&gt;NATURAL JOIN&lt;/code&gt; behaves like &lt;code&gt;CROSS JOIN&lt;/code&gt;.[1] SQLite's wording differs: it says &lt;code&gt;NATURAL&lt;/code&gt; "has no effect" in that case.[3]&lt;/p&gt;

&lt;p&gt;MySQL documents the coalesced columns with its own example. For tables &lt;code&gt;t1(a, b)&lt;/code&gt; holding 1/x and 2/y, and &lt;code&gt;t2(a, c)&lt;/code&gt; holding 2/z and 3/w, &lt;code&gt;NATURAL LEFT JOIN&lt;/code&gt; returns columns a, b, c with the rows 1/x/NULL and 2/y/z. The &lt;code&gt;NATURAL RIGHT JOIN&lt;/code&gt; returns columns a, c, b with the rows 2/z/y and 3/w/NULL.[2] The coalesced column &lt;code&gt;a&lt;/code&gt; takes its value from the inner table of the join, so the left join shows values of &lt;code&gt;t1.a&lt;/code&gt; and the right join shows values of &lt;code&gt;t2.a&lt;/code&gt;.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  The ON versus WHERE trap on outer joins
&lt;/h2&gt;

&lt;p&gt;On an inner join, a filter in &lt;code&gt;ON&lt;/code&gt; and the same filter in &lt;code&gt;WHERE&lt;/code&gt; give identical results. On an outer join they do not. PostgreSQL shows both versions on the same data.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'xxx'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c1"&gt;-----+------+-----+-------&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;xxx&lt;/span&gt;
   &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;
   &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'xxx'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="c1"&gt;-----+------+-----+-------&lt;/span&gt;
   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;    &lt;span class="o"&gt;|&lt;/span&gt;   &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;xxx&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The docs give the reason: a restriction in &lt;code&gt;ON&lt;/code&gt; is processed before the join, while a restriction in &lt;code&gt;WHERE&lt;/code&gt; is processed after it. "That does not matter with inner joins, but it matters a lot with outer joins."[1] The first query keeps all three left rows. The second returns one row, because the unmatched rows carry NULL in &lt;code&gt;t2.value&lt;/code&gt;, and &lt;code&gt;WHERE&lt;/code&gt; excludes rows that evaluate to false or NULL.[3] A &lt;code&gt;WHERE&lt;/code&gt; filter on the right table's columns quietly turns your LEFT JOIN into an inner join. MySQL's manual states the working division of labor: &lt;code&gt;ON&lt;/code&gt; specifies how tables are joined, and &lt;code&gt;WHERE&lt;/code&gt; restricts which rows appear in the result.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Find rows with no match: the anti-join
&lt;/h2&gt;

&lt;p&gt;MySQL documents a pattern that uses the NULL padding on purpose. When a &lt;code&gt;LEFT JOIN&lt;/code&gt; finds no matching right row, it uses a row of NULLs for the right table, so you can filter for those rows.[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;left_tbl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;left_tbl&lt;/span&gt; &lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;right_tbl&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;left_tbl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;right_tbl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;right_tbl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This returns every row in &lt;code&gt;left_tbl&lt;/code&gt; whose &lt;code&gt;id&lt;/code&gt; is not present in &lt;code&gt;right_tbl&lt;/code&gt;.[2] Test the NULL on a column that cannot be NULL in real data, such as the right table's key, or a genuine NULL will look like a missing row. That is a consequence of the padding rule, not something the sources spell out, so check your schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  Self-joins need aliases
&lt;/h2&gt;

&lt;p&gt;To join a table to itself, give each use a different alias. PostgreSQL's example pairs a parent row with a child row in one &lt;code&gt;people&lt;/code&gt; table.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;mother&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;mother&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mother_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you alias a table you cannot refer to it by its original name elsewhere in the query. The docs mark &lt;code&gt;SELECT * FROM my_table AS m WHERE my_table.a &amp;gt; 5&lt;/code&gt; as wrong.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Which databases support which joins
&lt;/h2&gt;

&lt;p&gt;The PostgreSQL syntax lists &lt;code&gt;INNER&lt;/code&gt;, &lt;code&gt;LEFT&lt;/code&gt;, &lt;code&gt;RIGHT&lt;/code&gt; and &lt;code&gt;FULL&lt;/code&gt; outer joins, plus &lt;code&gt;CROSS&lt;/code&gt; and &lt;code&gt;NATURAL&lt;/code&gt;.[1] SQLite's SELECT page describes &lt;code&gt;RIGHT&lt;/code&gt; and &lt;code&gt;FULL&lt;/code&gt; joins, and defines a FULL join as a combination of a LEFT JOIN and a RIGHT JOIN.[3] The page does not tell you which SQLite release added them, so check the version you ship.&lt;/p&gt;

&lt;p&gt;MySQL is the one to watch. The MySQL 8.4 join grammar lists &lt;code&gt;{LEFT|RIGHT} [OUTER] JOIN&lt;/code&gt; and &lt;code&gt;[INNER | CROSS] JOIN&lt;/code&gt;, and no &lt;code&gt;FULL&lt;/code&gt; keyword.[2] If a query written for PostgreSQL uses &lt;code&gt;FULL JOIN&lt;/code&gt;, expect to rewrite it when it moves to MySQL. The same page says &lt;code&gt;JOIN&lt;/code&gt;, &lt;code&gt;CROSS JOIN&lt;/code&gt; and &lt;code&gt;INNER JOIN&lt;/code&gt; are syntactic equivalents in MySQL, while in standard SQL they are not: &lt;code&gt;INNER JOIN&lt;/code&gt; takes an &lt;code&gt;ON&lt;/code&gt; clause and &lt;code&gt;CROSS JOIN&lt;/code&gt; does not.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Bookmarkable reference: what breaks
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Situation&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Filter on the right table in &lt;code&gt;WHERE&lt;/code&gt; after a LEFT JOIN | Unmatched rows are removed, so the query behaves like an inner join. PostgreSQL's example drops from 3 rows to 1[1] | Put the condition in &lt;code&gt;ON&lt;/code&gt;, or test &lt;code&gt;IS NULL&lt;/code&gt; deliberately |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;NATURAL JOIN&lt;/code&gt; on tables that change | A new column with a shared name becomes part of the join condition[1] | Use &lt;code&gt;USING (col)&lt;/code&gt; or &lt;code&gt;ON&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Comma mixed with &lt;code&gt;JOIN&lt;/code&gt; in MySQL | &lt;code&gt;JOIN&lt;/code&gt; binds tighter than the comma, so &lt;code&gt;t1, t2 JOIN t3 ON (t1.i1 = t3.i3)&lt;/code&gt; raises &lt;code&gt;Unknown column 't1.i1' in 'on clause'&lt;/code&gt;[2] | Use &lt;code&gt;JOIN&lt;/code&gt; everywhere, or parenthesize &lt;code&gt;(t1, t2)&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;ON&lt;/code&gt; refers to a table not yet joined | &lt;code&gt;t1 JOIN t2 ON (i1 = i3) JOIN t3&lt;/code&gt; fails with &lt;code&gt;Unknown column 'i3' in 'on clause'&lt;/code&gt; because &lt;code&gt;ON&lt;/code&gt; sees only its operands[2] | Move the condition to the join that has both tables |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;FULL JOIN&lt;/code&gt; in MySQL | The 8.4 grammar lists no &lt;code&gt;FULL&lt;/code&gt; keyword[2] | Rewrite the query for MySQL, or use a database that lists it |&lt;/p&gt;

&lt;p&gt;| One-to-many relationship | An inner join gives a row for each matching row in T2, so a left row with 3 matches appears 3 times[1] | Aggregate the many side first, or expect the repeats |&lt;/p&gt;

&lt;p&gt;| No join condition | Cartesian product, N * M rows[1] | Add &lt;code&gt;ON&lt;/code&gt; or &lt;code&gt;USING&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;RIGHT JOIN&lt;/code&gt; in shared code | Works, but MySQL recommends &lt;code&gt;LEFT JOIN&lt;/code&gt; for portability[2] | Swap the table order and use &lt;code&gt;LEFT&lt;/code&gt; |&lt;/p&gt;

&lt;h2&gt;
  
  
  The MySQL comma precedence error, in full
&lt;/h2&gt;

&lt;p&gt;This is the join mistake that fails loudest, because the error message points at the wrong table. The MySQL manual builds the failing case from three single-row tables.[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i1&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j1&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i2&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j2&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i3&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j3&lt;/span&gt; &lt;span class="kt"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Fails: Unknown column 't1.i1' in 'on clause'&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Works: parentheses group t1 and t2 as one operand&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Works: JOIN instead of the comma&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manual explains that &lt;code&gt;t1, t2 JOIN t3&lt;/code&gt; is read as &lt;code&gt;(t1, (t2 JOIN t3))&lt;/code&gt;, so the &lt;code&gt;ON&lt;/code&gt; clause only sees &lt;code&gt;t2&lt;/code&gt; and &lt;code&gt;t3&lt;/code&gt;.[2] PostgreSQL warns about the same thing: &lt;code&gt;FROM T1, T2 INNER JOIN T3 ON condition&lt;/code&gt; is not the same as the &lt;code&gt;CROSS JOIN&lt;/code&gt; form, because the condition cannot reference &lt;code&gt;T1&lt;/code&gt; there.[1] The habit that avoids all of it is to write explicit &lt;code&gt;JOIN&lt;/code&gt; keywords and no commas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reaching for LEFT JOIN, then filtering the right side in WHERE.&lt;/strong&gt; You asked to keep every left row and then deleted the unmatched ones. Move the filter into &lt;code&gt;ON&lt;/code&gt; if you want to restrict which right rows are matched, as in the PostgreSQL example above.[1]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgetting that a join can multiply rows.&lt;/strong&gt; The inner join definition gives one output row per matching pair.[1] Summing a column from the one side after joining the many side counts it once per match. Check the row count before and after.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using SELECT * with ON.&lt;/strong&gt; &lt;code&gt;JOIN ON&lt;/code&gt; returns all columns from T1 followed by all columns from T2, so a shared key appears twice, while &lt;code&gt;JOIN USING&lt;/code&gt; returns each listed pair once.[1] List the columns you want instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Treating CROSS JOIN as a mistake.&lt;/strong&gt; It is a legitimate join when you want every combination, such as a date list against a product list. The mistake is producing one by omission. SQLite adds a wrinkle: its &lt;code&gt;CROSS JOIN&lt;/code&gt; returns the same result as &lt;code&gt;INNER JOIN&lt;/code&gt;, but stops the optimizer from reordering the tables, and the SQLite docs advise avoiding it except where you want that manual control.[3]&lt;/p&gt;

&lt;p&gt;When a join query grows past a screen, readability is the next bug. Run it through the &lt;a href="https://dev.to/tools/sql-formatter"&gt;SQL formatter&lt;/a&gt; so each &lt;code&gt;JOIN&lt;/code&gt; and &lt;code&gt;ON&lt;/code&gt; sits on its own line, then check the conditions one join at a time. For what to do when the query is correct but slow, see the guide to &lt;a href="https://dev.to/blogs/sql-performance-optimization-indexing-query-tuning-2026"&gt;SQL performance, indexing and query tuning&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing a join in practice
&lt;/h2&gt;

&lt;p&gt;Start from the question. If you need only records that exist in both tables, use &lt;code&gt;INNER JOIN&lt;/code&gt;. If the left table is your list of record, such as customers, and the right is optional detail, such as orders, use &lt;code&gt;LEFT JOIN&lt;/code&gt;. If you want the customers who have no orders, add the &lt;code&gt;IS NULL&lt;/code&gt; filter on the right key. If you must see unmatched rows from both sides, such as when reconciling two systems, use &lt;code&gt;FULL JOIN&lt;/code&gt; and confirm your database lists it. Use &lt;code&gt;CROSS JOIN&lt;/code&gt; for combinations, and write &lt;code&gt;USING&lt;/code&gt; or &lt;code&gt;ON&lt;/code&gt; in place of &lt;code&gt;NATURAL&lt;/code&gt;. Prefer &lt;code&gt;LEFT&lt;/code&gt; over &lt;code&gt;RIGHT&lt;/code&gt;, since you can always swap the table order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.postgresql.org/docs/current/queries-table-expressions.html" rel="noopener noreferrer"&gt;Table Expressions, PostgreSQL documentation (accessed December 3, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.mysql.com/doc/refman/8.4/en/join.html" rel="noopener noreferrer"&gt;JOIN Clause, MySQL 8.4 Reference Manual (accessed December 3, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://www.sqlite.org/lang_select.html" rel="noopener noreferrer"&gt;SELECT, SQLite documentation (accessed December 3, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/sql-join-types-explained" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sqljoin</category>
      <category>sqljoins</category>
      <category>innerjoin</category>
      <category>leftjoin</category>
    </item>
    <item>
      <title>Vitest vs Jest: Setup, Migration, Differences</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Wed, 02 Dec 2026 01:21:36 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/vitest-vs-jest-setup-migration-differences-m6k</link>
      <guid>https://dev.to/akaranjkar08/vitest-vs-jest-setup-migration-differences-m6k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Vitest is a test framework powered by Vite. It needs Vite 6.4.0 or newer and Node.js 22.12.0 or newer, installs with &lt;code&gt;npm install -D vitest&lt;/code&gt;, and reads your existing &lt;code&gt;vite.config.*&lt;/code&gt; so tests share the app's plugins.&lt;/strong&gt;[1] The verdict against Jest: if your app already builds with Vite, pick Vitest, because its docs call a second test pipeline "not justifiable".[3] Jest's own docs say it is not supported by Vite.[7] Stay on Jest when a webpack or Babel setup works and you have no reason to touch it. Below: setup, a first test, shared config, the comparison table, migration steps and what breaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Vitest is and what it needs
&lt;/h2&gt;

&lt;p&gt;The docs describe Vitest (pronounced "veetest") as a next generation testing framework powered by Vite.[1] The project's pitch is a test runner that uses the same configuration as your app, so dev, build and test share one transformation pipeline.[4]&lt;/p&gt;

&lt;p&gt;Check the runtime before anything else. The requirement is hard, not a suggestion: Vitest 5.0 does not support older Vite or Node.js versions and "may" produce unexpected errors on them.[10] The GitHub releases page marked v5.1.2 as the latest release, published November 25, 2026, with a v5.2.0-beta.1 pre-release dated November 30.[9]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Requirement&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Vite | &amp;gt;= 6.4.0[1] |&lt;/p&gt;

&lt;p&gt;| Node.js | &amp;gt;= 22.12.0[1] |&lt;/p&gt;

&lt;p&gt;| Test file names | Must contain &lt;code&gt;.test.&lt;/code&gt; or &lt;code&gt;.spec.&lt;/code&gt; by default[1] |&lt;/p&gt;

&lt;p&gt;| Yarn | Run &lt;code&gt;yarn add -D vite&lt;/code&gt; too. Vite is a required peer dependency and Yarn does not install peers[10] |&lt;/p&gt;

&lt;p&gt;| Default environment | &lt;code&gt;node&lt;/code&gt;. &lt;code&gt;jsdom&lt;/code&gt;, &lt;code&gt;happy-dom&lt;/code&gt; and &lt;code&gt;edge-runtime&lt;/code&gt; are options[6] |&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Vitest and run a first test
&lt;/h2&gt;

&lt;p&gt;Install it as a dev dependency. The docs recommend a local copy in &lt;code&gt;package.json&lt;/code&gt; over running it ad hoc with &lt;code&gt;npx vitest&lt;/code&gt;, and they suggest adding the &lt;code&gt;.vitest/&lt;/code&gt; directory, where Vitest stores generated artifacts, to &lt;code&gt;.gitignore&lt;/code&gt;.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -D vitest

&lt;span class="c"&gt;# .gitignore&lt;/span&gt;
&lt;span class="c"&gt;# Vitest reports and artifacts&lt;/span&gt;
.vitest/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The getting-started test is a function that adds two numbers.[1] Note the explicit import from &lt;code&gt;vitest&lt;/code&gt;. Globals are off by default, a difference that matters later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// sum.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// sum.test.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'vitest'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./sum.js'&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'adds 1 + 2 to equal 3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;"test": "vitest"&lt;/code&gt; to the &lt;code&gt;scripts&lt;/code&gt; section of &lt;code&gt;package.json&lt;/code&gt; and run &lt;code&gt;npm run test&lt;/code&gt;. That starts watch mode, which Vitest enables by default.[1][4] For a single pass, as in CI, use &lt;code&gt;vitest run&lt;/code&gt;. It also accepts flags such as &lt;code&gt;--reporter&lt;/code&gt; and &lt;code&gt;--coverage&lt;/code&gt;.[1]&lt;/p&gt;

&lt;p&gt;One trap for Bun users: use &lt;code&gt;bun run test&lt;/code&gt;, not &lt;code&gt;bun test&lt;/code&gt;. The second command launches Bun's own test runner, not Vitest.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Share config with vite.config
&lt;/h2&gt;

&lt;p&gt;This is the real reason to choose Vitest. It reads &lt;code&gt;vite.config.*&lt;/code&gt; by default, so existing Vite plugins and configuration work without a second setup. For test-only settings you can add a dedicated &lt;code&gt;vitest.config.*&lt;/code&gt;.[1] The test options live under a &lt;code&gt;test&lt;/code&gt; key, and &lt;code&gt;defineConfig&lt;/code&gt; comes from &lt;code&gt;vitest/config&lt;/code&gt;.[5]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// vitest.config.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'vitest/config'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@vitejs/plugin-react'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;globals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'jsdom'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;react()&lt;/code&gt; plugin line mirrors a plugin example on the migration page; &lt;code&gt;globals&lt;/code&gt; and &lt;code&gt;environment&lt;/code&gt; are documented config options.[5][6][10] If you set &lt;code&gt;globals: true&lt;/code&gt; and use TypeScript, add &lt;code&gt;vitest/globals&lt;/code&gt; to &lt;code&gt;compilerOptions.types&lt;/code&gt; in &lt;code&gt;tsconfig.json&lt;/code&gt;. If you set &lt;code&gt;environment: 'jsdom'&lt;/code&gt;, &lt;code&gt;vitest/jsdom&lt;/code&gt; is the types entry for the &lt;code&gt;jsdom&lt;/code&gt; global.[5][6] To change the environment for one file only, put a &lt;code&gt;@vitest-environment&lt;/code&gt; docblock or comment at the top. For compatibility, &lt;code&gt;@jest-environment&lt;/code&gt; is accepted too.[6]&lt;/p&gt;

&lt;h2&gt;
  
  
  Vitest vs Jest
&lt;/h2&gt;

&lt;p&gt;The two share an API shape (&lt;code&gt;it&lt;/code&gt;, &lt;code&gt;expect&lt;/code&gt;, snapshots, mocks, coverage), so the choice comes down to the pipeline underneath.[3] Vitest's comparison page says it is a drop-in replacement for Jest in most projects, and that is the project's claim about its own tool.[3]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Vitest&lt;/th&gt;
&lt;th&gt;Jest&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Transform pipeline | Vite transforms files, shared with dev and build[4] | Its own pipeline. &lt;code&gt;babel-jest&lt;/code&gt; transforms files automatically when a Babel config exists, or you pick a transformer such as ts-jest[7] |&lt;/p&gt;

&lt;p&gt;| Vite support | Built for Vite from the start[4] | Docs: "not supported by Vite"; vite-jest does not work with Vite after 2.4.2[7] |&lt;/p&gt;

&lt;p&gt;| TypeScript | Handled by the Vite pipeline[3] | Via Babel (no type-checking while tests run) or ts-jest[7] |&lt;/p&gt;

&lt;p&gt;| ES modules | Files go through Vite's plugin system[3] | "Experimental" support; needs &lt;code&gt;--experimental-vm-modules&lt;/code&gt; and either &lt;code&gt;transform: {}&lt;/code&gt; or an ESM-emitting transformer[8] |&lt;/p&gt;

&lt;p&gt;| Globals (&lt;code&gt;describe&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;expect&lt;/code&gt;) | Off by default (&lt;code&gt;globals: false&lt;/code&gt;)[5] | On by default[2] |&lt;/p&gt;

&lt;p&gt;| Mock namespace | &lt;code&gt;vi&lt;/code&gt;, imported from &lt;code&gt;vitest&lt;/code&gt;[2] | &lt;code&gt;jest&lt;/code&gt;; in ESM import it from &lt;code&gt;@jest/globals&lt;/code&gt;[8] |&lt;/p&gt;

&lt;p&gt;| Config file | &lt;code&gt;vite.config.*&lt;/code&gt; or &lt;code&gt;vitest.config.*&lt;/code&gt;[1] | &lt;code&gt;jest.config.js&lt;/code&gt;, generated by &lt;code&gt;npm init jest@latest&lt;/code&gt;[7] |&lt;/p&gt;

&lt;p&gt;On speed, the Vitest docs say it uses worker threads to run as much as possible in parallel and that "some ports have seen test running an order of magnitude faster."[4] That is vendor-reported with no benchmark attached. Time your own suite before you sell the migration to your team.&lt;/p&gt;

&lt;p&gt;The honest limit: both run in Node-based environments such as jsdom, which implements only part of the browser. The Vitest docs list &lt;code&gt;window.navigation&lt;/code&gt; and layout properties like &lt;code&gt;offsetTop&lt;/code&gt; as jsdom gaps, and suggest real-browser runners (Cypress, Playwright, WebdriverIO) alongside Vitest for browser-level checks.[3] Vitest also has its own browser mode, with documented limitations.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Migrate from Jest to Vitest
&lt;/h2&gt;

&lt;p&gt;The migration page opens by saying Vitest was designed with a Jest-compatible API, but you "may still run into" differences.[2] A workable order:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| 1 | Check Node.js is 22.12.0 or newer and Vite is 6.4.0 or newer[1] |&lt;/p&gt;

&lt;p&gt;| 2 | Install Vitest with &lt;code&gt;npm install -D vitest&lt;/code&gt;[1] |&lt;/p&gt;

&lt;p&gt;| 3 | Either set &lt;code&gt;globals: true&lt;/code&gt; or import &lt;code&gt;describe&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;expect&lt;/code&gt; and &lt;code&gt;vi&lt;/code&gt; from &lt;code&gt;vitest&lt;/code&gt;[2] |&lt;/p&gt;

&lt;p&gt;| 4 | Replace &lt;code&gt;jest.*&lt;/code&gt; calls with &lt;code&gt;vi.*&lt;/code&gt; equivalents (table below) |&lt;/p&gt;

&lt;p&gt;| 5 | Replace &lt;code&gt;jest.mock&lt;/code&gt; factories that return a bare value with an object that names each export |&lt;/p&gt;

&lt;p&gt;| 6 | Change the &lt;code&gt;test&lt;/code&gt; script to &lt;code&gt;vitest&lt;/code&gt; (or &lt;code&gt;vitest run&lt;/code&gt; in CI) and run the suite |&lt;/p&gt;

&lt;p&gt;Step 5 is the one that trips most suites. In Jest, the factory's return value is the default export. In Vitest the factory must return an object with each export defined.[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Jest&lt;/span&gt;
&lt;span class="n"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'./some-path'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'hello'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Vitest&lt;/span&gt;
&lt;span class="n"&gt;vi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'./some-path'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'hello'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Partial mocks: requireActual becomes importActual&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cloneDeep&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;vi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;importActual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lodash/cloneDeep'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What breaks when you migrate
&lt;/h2&gt;

&lt;p&gt;These come straight from the official Jest migration page.[2] Search your suite for each one before the first run.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Jest habit&lt;/th&gt;
&lt;th&gt;Vitest behavior&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Globals available everywhere | Not provided by default. Libraries like &lt;code&gt;testing-library&lt;/code&gt; will not run automatic DOM cleanup with globals off[2] | &lt;code&gt;globals: true&lt;/code&gt;, or import from &lt;code&gt;vitest&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;mockReset&lt;/code&gt; gives an empty function returning &lt;code&gt;undefined&lt;/code&gt; | Resets to the original implementation, so &lt;code&gt;vi.fn(impl)&lt;/code&gt; goes back to &lt;code&gt;impl&lt;/code&gt;[2] | Re-stub if you relied on the empty function |&lt;/p&gt;

&lt;p&gt;| Factory return value is the default export | Factory must return an object with each export defined[2] | Wrap in &lt;code&gt;{ default: ... }&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;&amp;lt;root&amp;gt;/__mocks__&lt;/code&gt; loaded automatically | Not loaded unless &lt;code&gt;vi.mock()&lt;/code&gt; is called[2] | Call &lt;code&gt;vi.mock()&lt;/code&gt;, or mock inside &lt;code&gt;setupFiles&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;jest.requireActual&lt;/code&gt; | Use &lt;code&gt;vi.importActual&lt;/code&gt;[2] | Rename and &lt;code&gt;await&lt;/code&gt; it |&lt;/p&gt;

&lt;p&gt;| Mocks reach external libraries that use the module | You must name the library in &lt;code&gt;server.deps.inline&lt;/code&gt;[2] | &lt;code&gt;server.deps.inline: ["lib-name"]&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;done&lt;/code&gt; callback tests | Callback style unsupported[2] | Use &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; or return a Promise |&lt;/p&gt;

&lt;p&gt;| Hook returns a value | A returned function is treated as a teardown. Hooks run in a stack, not one after another[2] | Use braces so the hook returns nothing; set &lt;code&gt;sequence.hooks: 'list'&lt;/code&gt; for Jest order |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;jest.Mock&lt;/code&gt; types | No &lt;code&gt;jest&lt;/code&gt; namespace[2] | &lt;code&gt;import type { Mock } from 'vitest'&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Legacy fake timers | Not supported[2] | Use &lt;code&gt;vi.useFakeTimers()&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;jest.setTimeout(5_000)&lt;/code&gt; | Replace with &lt;code&gt;vi.setConfig({ testTimeout: 5_000 })&lt;/code&gt;[2] | Rename |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;-t 'math adds'&lt;/code&gt; | Names are joined with &lt;code&gt;&amp;gt;&lt;/code&gt;, so use &lt;code&gt;-t 'math &amp;gt; adds'&lt;/code&gt;[2] | Match one segment or use &lt;code&gt;'math.*adds'&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;JEST_WORKER_ID&lt;/code&gt; | Counterpart is &lt;code&gt;VITEST_POOL_ID&lt;/code&gt;; &lt;code&gt;VITEST_WORKER_ID&lt;/code&gt; is the unique worker id[2] | Rename the variable |&lt;/p&gt;

&lt;p&gt;Unchanged: like Jest, Vitest sets &lt;code&gt;NODE_ENV&lt;/code&gt; to &lt;code&gt;test&lt;/code&gt; if it was not already set.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Vitest 5 changes that hit a fresh migration
&lt;/h2&gt;

&lt;p&gt;The main migration page now covers upgrading to Vitest 5.0, and several of its changes bite someone arriving from Jest.[10]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Change in 5.0&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;clearMocks&lt;/code&gt; defaults to &lt;code&gt;true&lt;/code&gt; | Calls &lt;code&gt;vi.clearAllMocks()&lt;/code&gt; before every test, clearing mock call history but keeping implementations. Calls recorded in &lt;code&gt;beforeAll&lt;/code&gt; or a setup file are the most affected. Set &lt;code&gt;clearMocks: false&lt;/code&gt; to keep the old behavior[10] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;vi.mock&lt;/code&gt;, &lt;code&gt;vi.unmock&lt;/code&gt;, &lt;code&gt;vi.hoisted&lt;/code&gt; inside a block | Now throws instead of warning, because the call is hoisted to the top of the file. Move it to the top level. &lt;code&gt;vi.doMock&lt;/code&gt; and &lt;code&gt;vi.doUnmock&lt;/code&gt; are not hoisted and may be called anywhere[10] |&lt;/p&gt;

&lt;p&gt;| Unawaited &lt;code&gt;resolves&lt;/code&gt; / &lt;code&gt;rejects&lt;/code&gt; | The test fails. Before 5.0 Vitest awaited them at the end and printed a warning[10] |&lt;/p&gt;

&lt;p&gt;| Config lookup | Vitest no longer searches parent directories for config files. Pass &lt;code&gt;--config ../vitest.config.ts&lt;/code&gt; from a subdirectory[10] |&lt;/p&gt;

&lt;p&gt;| Worker ids | &lt;code&gt;VITEST_POOL_ID&lt;/code&gt; and &lt;code&gt;VITEST_WORKER_ID&lt;/code&gt; now start at 1, so per-worker database names or array indexes need an update[10] |&lt;/p&gt;

&lt;p&gt;| JSON and JUnit reporters | Write to a file under &lt;code&gt;.vitest/&lt;/code&gt; by default instead of stdout, so &lt;code&gt;vitest --reporter=json | jq&lt;/code&gt; stops working unless you set the reporter's &lt;code&gt;stdout&lt;/code&gt; option[10] |&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;p&gt;Four mistakes cause most of the "Vitest is broken" reports, and each one traces to a documented default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Turning on globals in config but not in TypeScript.&lt;/strong&gt; &lt;code&gt;globals: true&lt;/code&gt; makes the runtime work, yet the editor reports errors until &lt;code&gt;vitest/globals&lt;/code&gt; is in &lt;code&gt;types&lt;/code&gt;.[5] If you redefined &lt;code&gt;typeRoots&lt;/code&gt;, add &lt;code&gt;./node_modules&lt;/code&gt; back so &lt;code&gt;vitest/globals&lt;/code&gt; can be found.[5]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keeping globals off and wondering why DOM tests leak.&lt;/strong&gt; With globals disabled, &lt;code&gt;testing-library&lt;/code&gt; skips its automatic cleanup.[2] Either turn globals on or call cleanup yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Putting &lt;code&gt;vi.mock&lt;/code&gt; inside &lt;code&gt;describe&lt;/code&gt;.&lt;/strong&gt; It never ran where it was written, and from 5.0 it throws.[10] Hoist it to the top of the file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Running tests with the wrong command.&lt;/strong&gt; Bun's &lt;code&gt;bun test&lt;/code&gt; is not Vitest, and plain &lt;code&gt;vitest&lt;/code&gt; starts watch mode by default, so use &lt;code&gt;vitest run&lt;/code&gt; for a single pass.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  When to keep Jest
&lt;/h2&gt;

&lt;p&gt;Vitest's pitch rests on sharing Vite's pipeline, so the case weakens when the project is not on Vite. The docs still call Vitest "a solid alternative even for projects not using Vite".[4] The comparison page names a library built with esbuild or Rollup as an example.[3] Reasons to wait are practical. A large suite leans on &lt;code&gt;jest.mock&lt;/code&gt; factories that return default exports. It depends on automatic &lt;code&gt;__mocks__&lt;/code&gt; loading. It needs legacy timers, which Vitest does not support.[2] Each costs edits across many files, and the payoff is a faster feedback loop you have not yet measured on your code. Migrate one package or directory first, run both runners side by side, and compare the time and the failures before you move the rest.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vitest.dev/guide/" rel="noopener noreferrer"&gt;Getting Started, Vitest docs (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vitest.dev/guide/migration/jest" rel="noopener noreferrer"&gt;Migrating from Jest, Vitest docs (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vitest.dev/guide/comparisons" rel="noopener noreferrer"&gt;Comparisons with Other Test Runners, Vitest docs (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vitest.dev/guide/why" rel="noopener noreferrer"&gt;Why Vitest, Vitest docs (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vitest.dev/config/globals" rel="noopener noreferrer"&gt;globals, Vitest config reference (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vitest.dev/config/environment" rel="noopener noreferrer"&gt;environment, Vitest config reference (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://jestjs.io/docs/getting-started" rel="noopener noreferrer"&gt;Getting Started, Jest docs, version 30.5 (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://jestjs.io/docs/ecmascript-modules" rel="noopener noreferrer"&gt;ECMAScript Modules, Jest docs, version 30.5 (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/vitest-dev/vitest/releases" rel="noopener noreferrer"&gt;Releases, vitest-dev/vitest, GitHub (accessed December 2, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  10. &lt;a href="https://vitest.dev/guide/migration" rel="noopener noreferrer"&gt;Migrating to Vitest 5.0, Vitest docs (accessed December 2, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/vitest-vs-jest" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vitest</category>
      <category>vitestvs</category>
      <category>vitestsetup</category>
      <category>migratejest</category>
    </item>
    <item>
      <title>Hono Web Framework: Setup, Routing, Middleware</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Tue, 01 Dec 2026 01:25:31 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/hono-web-framework-setup-routing-middleware-3720</link>
      <guid>https://dev.to/akaranjkar08/hono-web-framework-setup-routing-middleware-3720</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hono is a small, zero-dependency web framework built on Web Standards (Request, Response, fetch) that runs the same application code on Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Netlify, AWS Lambda, Lambda@Edge and Node.js.&lt;/strong&gt;[1] The verdict: pick Hono when you want an Express-style API on an edge or multi-runtime target, with first-class TypeScript and built-in middleware. Skip it if you need a full-stack framework with an ORM and an admin panel, because Hono describes itself as a web application framework "without a frontend".[1] Below: setup, routing, the Context object, middleware, the five routers, validation, typed RPC, per-runtime entry points and a table of mistakes that bite people in practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Hono is
&lt;/h2&gt;

&lt;p&gt;The name means "flame" in Japanese.[1] The docs list five headline features: an ultrafast router (&lt;code&gt;RegExpRouter&lt;/code&gt;), a lightweight core (the &lt;code&gt;hono/tiny&lt;/code&gt; preset is under 14kB, with zero dependencies), multi-runtime support, built-in and third-party middleware, and TypeScript-first APIs.[1] The MIT-licensed project lives at github.com/honojs/hono; the repository page showed 33.2k stars and release v4.13.23 dated November 26, 2026 when checked for this article.[12]&lt;/p&gt;

&lt;p&gt;Because it is built on Web Standards, the application code stays the same everywhere. Only the entry point changes.[2]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Runtime&lt;/th&gt;
&lt;th&gt;Entry point&lt;/th&gt;
&lt;th&gt;Extra package&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Cloudflare Workers | &lt;code&gt;export default app&lt;/code&gt; | None. Wrangler runs and deploys it[10] |&lt;/p&gt;

&lt;p&gt;| Bun | &lt;code&gt;export default app&lt;/code&gt;, or an object with &lt;code&gt;port&lt;/code&gt; and &lt;code&gt;fetch&lt;/code&gt; | None. &lt;code&gt;@hono/bun&lt;/code&gt; only for static files[11] |&lt;/p&gt;

&lt;p&gt;| Node.js | &lt;code&gt;serve(app)&lt;/code&gt; from &lt;code&gt;@hono/node-server&lt;/code&gt; | &lt;code&gt;@hono/node-server&lt;/code&gt;[9] |&lt;/p&gt;

&lt;p&gt;| Deno, Fastly, Vercel, Netlify, AWS Lambda, Lambda@Edge | Listed as supported; each has its own guide | See the platform guide[1] |&lt;/p&gt;

&lt;p&gt;On Node.js, the docs say Hono was not designed for it at first but works through the adapter on versions above 18.x: 18.14.1+, 19.7.0+ and 20.0.0+.[9]&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up a Hono project
&lt;/h2&gt;

&lt;p&gt;The starter command is &lt;code&gt;create-hono&lt;/code&gt;. It asks which template you want. The list in the docs includes aws-lambda, bun, cloudflare-pages, cloudflare-workers, deno, fastly, nextjs, nodejs and vercel.[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create hono@latest my-app
&lt;span class="nb"&gt;cd&lt;/span&gt; my-app
npm i
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same page gives equivalents for yarn, pnpm, bun and deno. For an existing Bun project, &lt;code&gt;bun add hono&lt;/code&gt; is enough, plus a &lt;code&gt;dev&lt;/code&gt; script of &lt;code&gt;bun run --hot src/index.ts&lt;/code&gt;.[11] The dev server answers on port 8787 for Workers and port 3000 for Node.js and Bun.[2][9][11]&lt;/p&gt;

&lt;h2&gt;
  
  
  Routing and the Context object
&lt;/h2&gt;

&lt;p&gt;Every handler receives a &lt;code&gt;Context&lt;/code&gt; (conventionally &lt;code&gt;c&lt;/code&gt;) that exists for one request. It exposes the request through &lt;code&gt;c.req&lt;/code&gt;, sets the status and headers, and builds the response.[4]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello Hono!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/posts/:id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'page'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;param&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'X-Message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Hi!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'You want to see '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;' of '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Created!'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/api/hello'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Hello Hono!'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'List Books'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/:id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Get Book: '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;param&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those calls come straight from the Getting Started and Routing pages.[2][3] The response helpers are &lt;code&gt;c.text()&lt;/code&gt;, &lt;code&gt;c.json()&lt;/code&gt;, &lt;code&gt;c.html()&lt;/code&gt;, &lt;code&gt;c.body()&lt;/code&gt;, &lt;code&gt;c.redirect()&lt;/code&gt; (default status 302) and &lt;code&gt;c.notFound()&lt;/code&gt;. You can also return a raw &lt;code&gt;new Response(...)&lt;/code&gt;.[2][4]&lt;/p&gt;

&lt;h3&gt;
  
  
  Route pattern reference
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Path parameter | &lt;code&gt;/user/:name&lt;/code&gt; | Read with &lt;code&gt;c.req.param('name')&lt;/code&gt;, or all at once with &lt;code&gt;c.req.param()&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| Optional parameter | &lt;code&gt;/api/animal/:type?&lt;/code&gt; | Matches &lt;code&gt;/api/animal&lt;/code&gt; and &lt;code&gt;/api/animal/:type&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| Regexp | &lt;code&gt;/post/:date{[0-9]+}/:title{[a-z]+}&lt;/code&gt; | Constrains each parameter[3] |&lt;/p&gt;

&lt;p&gt;| Wildcard | &lt;code&gt;/wild/*/card&lt;/code&gt; | Wildcard in the middle of a path[3] |&lt;/p&gt;

&lt;p&gt;| Any method | &lt;code&gt;app.all('/hello', ...)&lt;/code&gt; | Handles every HTTP method[3] |&lt;/p&gt;

&lt;p&gt;| Custom method | &lt;code&gt;app.on('PURGE', '/cache', ...)&lt;/code&gt; | Handles a non-standard method[3] |&lt;/p&gt;

&lt;p&gt;| Base path | &lt;code&gt;new Hono().basePath('/api')&lt;/code&gt; | &lt;code&gt;/book&lt;/code&gt; becomes &lt;code&gt;/api/book&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;One rule decides most routing bugs: handlers and middleware run in registration order, and once a handler returns, processing stops.[3] Register &lt;code&gt;app.get('/book/a', ...)&lt;/code&gt; before &lt;code&gt;app.get('/book/:slug', ...)&lt;/code&gt;. Put a catch-all &lt;code&gt;*&lt;/code&gt; last if it is a fallback. Put it first and nothing below it ever runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Middleware
&lt;/h2&gt;

&lt;p&gt;The docs call the primitive that returns a &lt;code&gt;Response&lt;/code&gt; a "Handler". Middleware runs before and after the handler, like an onion.[5] Everything before &lt;code&gt;await next()&lt;/code&gt; runs on the way in; everything after runs on the way out, once the handler has produced a response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;etag&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono/etag'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono/logger'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;basicAuth&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono/basic-auth'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;etag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'X-Response-Time'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s1"&gt;'/admin/*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;basicAuth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'admin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'secret'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/admin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'You are authorized!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The timing middleware is the docs' own example; &lt;code&gt;etag()&lt;/code&gt; plus &lt;code&gt;logger()&lt;/code&gt; and the &lt;code&gt;basicAuth&lt;/code&gt; block also come from the docs.[1][2][5] Hardcoded credentials are for the demo only. Read them from your environment. On Workers that means &lt;code&gt;c.env&lt;/code&gt; inside a wrapper, covered below. For what each status code means when auth fails, see the &lt;a href="https://dev.to/blogs/401-vs-403-http-status-codes-explained"&gt;401 vs 403 explainer&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Built-in middleware and helpers
&lt;/h3&gt;

&lt;p&gt;The docs home page lists these as shipping with Hono.[1]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Need&lt;/th&gt;
&lt;th&gt;Import path or name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Basic and Bearer auth | &lt;code&gt;hono/basic-auth&lt;/code&gt;, Bearer Authentication |&lt;/p&gt;

&lt;p&gt;| JWT auth | JWT Authentication middleware |&lt;/p&gt;

&lt;p&gt;| CORS, ETag, compression | CORS, &lt;code&gt;hono/etag&lt;/code&gt;, Compress |&lt;/p&gt;

&lt;p&gt;| Caching and body size | Cache, Body Limit |&lt;/p&gt;

&lt;p&gt;| Logging and headers | &lt;code&gt;hono/logger&lt;/code&gt;, Secure Headers, Pretty JSON |&lt;/p&gt;

&lt;p&gt;| Cookies, HTML, JSX, streaming, SSG | Cookie, html, JSX, Streaming, SSG helpers |&lt;/p&gt;

&lt;p&gt;| Context Storage, Language | Context Storage, Language |&lt;/p&gt;

&lt;p&gt;The built-in list has no rate limiter, so you add one or return a &lt;code&gt;429&lt;/code&gt; yourself. The &lt;a href="https://dev.to/blogs/http-429-too-many-requests"&gt;HTTP 429 guide&lt;/a&gt; covers what a good one sends back.&lt;/p&gt;

&lt;p&gt;To pass values from middleware to handlers, use &lt;code&gt;c.set('key', value)&lt;/code&gt; and &lt;code&gt;c.get('key')&lt;/code&gt;. They live only for the current request. Declare a &lt;code&gt;Variables&lt;/code&gt; type on the &lt;code&gt;Hono&lt;/code&gt; generic to type them.[4]&lt;/p&gt;

&lt;h2&gt;
  
  
  The five routers
&lt;/h2&gt;

&lt;p&gt;Routing speed is a headline feature, and the router is swappable. The docs describe five.[6]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Router&lt;/th&gt;
&lt;th&gt;Idea&lt;/th&gt;
&lt;th&gt;Trade-off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| RegExpRouter | Compiles all routes into one large regular expression before dispatch | Fastest, but does not support every pattern[6] |&lt;/p&gt;

&lt;p&gt;| TrieRouter | Trie-tree matching | Slower than RegExpRouter, supports all patterns[6] |&lt;/p&gt;

&lt;p&gt;| SmartRouter | Picks the best router from the registered routes at startup | The default wraps RegExpRouter and TrieRouter[6] |&lt;/p&gt;

&lt;p&gt;| LinearRouter | Adds routes without compiling strings | Fast registration, for environments that initialize on every request[6] |&lt;/p&gt;

&lt;p&gt;| PatternRouter | Adds and matches patterns directly | Smallest: an app using only it is under 15KB[6] |&lt;/p&gt;

&lt;p&gt;Most apps never touch this. The default &lt;code&gt;SmartRouter&lt;/code&gt; handles it. The docs also publish a project-reported Cloudflare Workers router benchmark where Hono scored 402,820 ops/sec against 212,598 for itty-router, 297,036 for sunder and 197,345 for worktop.[1] That is the project's own measurement of routers only, not an end-to-end throughput test, so treat it as a pointer rather than a promise. Your database and network will dominate real latency.&lt;/p&gt;

&lt;p&gt;On size, the project-reported figures are that &lt;code&gt;hono/tiny&lt;/code&gt; is under 14KB minified, against 572KB for Express. The GitHub README says under 12kB for the same preset, so the two project pages disagree slightly.[1][12] Either way it is a small core. Middleware and adapters are bundled only when you import them.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation and typed RPC
&lt;/h2&gt;

&lt;p&gt;Hono ships only a thin validator and recommends a third-party library. The &lt;code&gt;validator&lt;/code&gt; function from &lt;code&gt;hono/validator&lt;/code&gt; works as middleware, with targets &lt;code&gt;json&lt;/code&gt;, &lt;code&gt;form&lt;/code&gt;, &lt;code&gt;query&lt;/code&gt;, &lt;code&gt;header&lt;/code&gt;, &lt;code&gt;param&lt;/code&gt; and &lt;code&gt;cookie&lt;/code&gt;.[7] The Zod middleware and the Standard Schema middleware are separate packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// server.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;zValidator&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@hono/zod-validator'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zod'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s1"&gt;'/posts'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;zValidator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'form'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Created!'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;AppType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="n"&gt;route&lt;/span&gt;

&lt;span class="c1"&gt;// client.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;hc&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono/client'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;AppType&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'./server'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'http://localhost:8787/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Hello'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Hono is a cool project'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the RPC feature: export &lt;code&gt;typeof&lt;/code&gt; your app (or route), pass it to &lt;code&gt;hc&lt;/code&gt; as a generic, and the client infers both the validated input and the &lt;code&gt;c.json()&lt;/code&gt; output.[8] Specify status codes in &lt;code&gt;c.json()&lt;/code&gt; (for example &lt;code&gt;404&lt;/code&gt;) and the client can narrow on &lt;code&gt;res.status&lt;/code&gt;. Install with &lt;code&gt;npm i @hono/zod-validator zod&lt;/code&gt;.[7][8] For monorepos, the docs ask for &lt;code&gt;"strict": true&lt;/code&gt; in both the client and server tsconfig files.[8]&lt;/p&gt;

&lt;h2&gt;
  
  
  Runtime specifics: bindings and Node.js
&lt;/h2&gt;

&lt;p&gt;On Cloudflare Workers, environment variables, KV namespaces, R2 buckets and Durable Objects arrive as bindings on &lt;code&gt;c.env&lt;/code&gt;. Pass a type to the &lt;code&gt;Hono&lt;/code&gt; generic to get typed access.[10] On Node.js you wrap the app with the adapter.[9]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Cloudflare Workers&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;basicAuth&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'hono/basic-auth'&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Bindings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="no"&gt;USERNAME&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="no"&gt;PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Hono&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/auth/*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;basicAuth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;USERNAME&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PASSWORD&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;

&lt;span class="c1"&gt;// Node.js (separate file; import your app from the module above)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;serve&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@hono/node-server'&lt;/span&gt;

&lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8787&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wrapper that builds &lt;code&gt;basicAuth&lt;/code&gt; inside the handler is the documented pattern for using secrets in middleware on Workers.[10] To combine Hono with other Workers event handlers such as &lt;code&gt;scheduled&lt;/code&gt;, export an object with &lt;code&gt;fetch: app.fetch&lt;/code&gt; plus the extra handler.[10]&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks: common mistakes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mistake&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Catch-all &lt;code&gt;app.get('*', ...)&lt;/code&gt; registered before specific routes | Specific routes are never dispatched[3] | Register specific routes first, fallback last |&lt;/p&gt;

&lt;p&gt;| Middleware registered below the handler | It does not run for that route[3] | Write &lt;code&gt;app.use()&lt;/code&gt; above the handlers it should wrap |&lt;/p&gt;

&lt;p&gt;| Calling &lt;code&gt;app.route('/two', two)&lt;/code&gt; before &lt;code&gt;two&lt;/code&gt; has its routes | 404, because &lt;code&gt;route()&lt;/code&gt; copies the routes stored at that moment[3] | Mount the innermost group first |&lt;/p&gt;

&lt;p&gt;| Validating &lt;code&gt;json&lt;/code&gt; or &lt;code&gt;form&lt;/code&gt; without a matching &lt;code&gt;Content-Type&lt;/code&gt; | The callback receives &lt;code&gt;{}&lt;/code&gt;[7] | Send the header, including in &lt;code&gt;app.request()&lt;/code&gt; tests |&lt;/p&gt;

&lt;p&gt;| Header validator keyed &lt;code&gt;Idempotency-Key&lt;/code&gt; | Value is always undefined[7] | Use the lowercase key &lt;code&gt;idempotency-key&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Reading &lt;code&gt;process.env&lt;/code&gt; on Workers | Not available by default[10] | Use &lt;code&gt;c.env&lt;/code&gt;, or enable the &lt;code&gt;nodejs_compat_populate_process_env&lt;/code&gt; flag |&lt;/p&gt;

&lt;p&gt;| Returning &lt;code&gt;c.notFound()&lt;/code&gt; in an RPC route | Client data is &lt;code&gt;unknown&lt;/code&gt;[8] | Return &lt;code&gt;c.json({ error: 'not found' }, 404)&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Handler returns a &lt;code&gt;.then()&lt;/code&gt; chain | Client infers &lt;code&gt;unknown&lt;/code&gt;[8] | Use &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;serveStatic&lt;/code&gt; &lt;code&gt;root&lt;/code&gt; on Node.js | Resolves from &lt;code&gt;process.cwd()&lt;/code&gt;, so it breaks if you start the process elsewhere[9] | Build the path from &lt;code&gt;import.meta.url&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| Protecting static files with &lt;code&gt;app.use('/admin/*', auth)&lt;/code&gt; | Route matching is case-sensitive but Windows and macOS file systems may not be, so &lt;code&gt;/ADMIN/secret.txt&lt;/code&gt; can skip the middleware[9][11] | Keep protected files outside the served directory |&lt;/p&gt;

&lt;p&gt;Two more from the Context docs. &lt;code&gt;ContextVariableMap&lt;/code&gt; adds types globally, so &lt;code&gt;c.get('result')&lt;/code&gt; looks typed even in routes where the middleware never ran, which hides undefined bugs.[4] And on a large RPC app, type inference gets expensive: the docs warn that IDE speed drops as routes grow and suggest compiling the client type ahead of time or splitting the app into several clients.[8]&lt;/p&gt;

&lt;h2&gt;
  
  
  When Hono fits, and when it does not
&lt;/h2&gt;

&lt;p&gt;Hono fits web APIs, backend proxies, CDN-edge logic and base servers for libraries. The docs name those use-cases and list cdnjs, Cloudflare D1 and Workers KV internals, Unkey, OpenStatus and Clerk as production users.[1] It fits teams that already write TypeScript and want request and response types to follow them from the route to the client.&lt;/p&gt;

&lt;p&gt;It fits less well when you want conventions handed to you. There is no bundled ORM, user-account system or admin UI, only middleware and helpers (the docs do list full-stack applications as a use-case, but you assemble that stack yourself). Adapters for platform features such as WebSocket or static files ship as separate packages, and their names differ per runtime, so a "same code everywhere" app still has a few runtime-specific lines.[2][9][11] That is the honest cost of portability: the routing and handler code moves, the edges do not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/" rel="noopener noreferrer"&gt;Hono, Web framework built on Web Standards, hono.dev docs home (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/getting-started/basic" rel="noopener noreferrer"&gt;Getting Started, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/api/routing" rel="noopener noreferrer"&gt;Routing, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/api/context" rel="noopener noreferrer"&gt;Context, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/concepts/middleware" rel="noopener noreferrer"&gt;Middleware, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/concepts/routers" rel="noopener noreferrer"&gt;Routers, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/guides/validation" rel="noopener noreferrer"&gt;Validation, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/guides/rpc" rel="noopener noreferrer"&gt;RPC, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/getting-started/nodejs" rel="noopener noreferrer"&gt;Node.js, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/getting-started/cloudflare-workers" rel="noopener noreferrer"&gt;Cloudflare Workers, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hono.dev/docs/getting-started/bun" rel="noopener noreferrer"&gt;Bun, Hono docs (accessed December 1, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  12. &lt;a href="https://github.com/honojs/hono" rel="noopener noreferrer"&gt;honojs/hono, README, license and releases, GitHub (accessed December 1, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/hono-web-framework-guide" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>hono</category>
      <category>honoframework</category>
      <category>honoweb</category>
      <category>honojs</category>
    </item>
    <item>
      <title>uv Python: Install and Manage Python Versions</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Mon, 30 Nov 2026 01:21:46 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/uv-python-install-and-manage-python-versions-b3</link>
      <guid>https://dev.to/akaranjkar08/uv-python-install-and-manage-python-versions-b3</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;code&gt;uv python&lt;/code&gt; is the command group in uv that installs, lists, finds, pins, upgrades and uninstalls Python versions.&lt;/strong&gt;[1] The core commands are &lt;code&gt;uv python install 3.12&lt;/code&gt; to download a version, &lt;code&gt;uv python list&lt;/code&gt; to see what is available, &lt;code&gt;uv python find&lt;/code&gt; to print the path of the interpreter uv would use, &lt;code&gt;uv python pin 3.12&lt;/code&gt; to write a &lt;code&gt;.python-version&lt;/code&gt; file, and &lt;code&gt;uv python uninstall 3.12&lt;/code&gt; to remove one.[1][2] You do not have to install anything first, because uv downloads a missing Python on demand by default.[1] This guide covers each command with examples, a reference table, and the edge cases that cause most confusion.&lt;/p&gt;

&lt;h2&gt;
  
  
  What uv python does
&lt;/h2&gt;

&lt;p&gt;uv separates Python installations into two kinds. A &lt;em&gt;managed&lt;/em&gt; installation is one uv installed itself. Everything else is a &lt;em&gt;system&lt;/em&gt; installation, including Pythons from your operating system and ones managed by other tools. A Python managed by &lt;code&gt;pyenv&lt;/code&gt; counts as a system Python to uv.[2]&lt;/p&gt;

&lt;p&gt;Python does not publish official distributable binaries, so uv downloads distributions from Astral's &lt;code&gt;python-build-standalone&lt;/code&gt; project for CPython. PyPy builds come from the PyPy project.[1][2] uv's docs describe these distributions as self-contained and highly portable. They contrast that with building from source, as &lt;code&gt;pyenv&lt;/code&gt; does, which requires preinstalled system dependencies, and note that creating optimized builds (with PGO and LTO enabled) is very slow.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Install a Python version
&lt;/h2&gt;

&lt;p&gt;With no argument, &lt;code&gt;uv python install&lt;/code&gt; installs the latest Python version. With an argument, it accepts the same request formats as the &lt;code&gt;--python&lt;/code&gt; flag on other commands.[1][2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# latest Python&lt;/span&gt;
uv python install

&lt;span class="c"&gt;# a minor version (resolves to the latest patch uv knows about)&lt;/span&gt;
uv python install 3.12

&lt;span class="c"&gt;# an exact patch, several versions at once, or a constraint&lt;/span&gt;
uv python install 3.12.3
uv python install 3.11 3.12
uv python install &lt;span class="s1"&gt;'&amp;gt;=3.8,=3.11'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, &lt;code&gt;list&lt;/code&gt; hides downloads for other platforms and old patch versions.[2] &lt;code&gt;find&lt;/code&gt; prints the path to the first available executable and understands the same request formats.[2] Use &lt;code&gt;uv python dir&lt;/code&gt; to print the managed installation directory, and add &lt;code&gt;--bin&lt;/code&gt; to print the executable directory instead.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Pin, upgrade and uninstall
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;uv python pin 3.12&lt;/code&gt; writes a &lt;code&gt;.python-version&lt;/code&gt; file in the current directory, and &lt;code&gt;uv python pin --global&lt;/code&gt; writes one in the user configuration directory.[2] The CLI reference also lists &lt;code&gt;--rm&lt;/code&gt; and &lt;code&gt;--resolved&lt;/code&gt; options for &lt;code&gt;pin&lt;/code&gt;.[3]&lt;/p&gt;

&lt;p&gt;Upgrades work on patch releases only. &lt;code&gt;uv python upgrade 3.12&lt;/code&gt; moves a managed 3.12 to the latest supported patch, and &lt;code&gt;uv python upgrade&lt;/code&gt; with no argument upgrades all managed versions. uv does not upgrade across minor versions, such as 3.12 to 3.13, because that can change dependency resolution.[2] Upgrades are not supported for PyPy, GraalPy or Pyodide.[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv python upgrade 3.12      &lt;span class="c"&gt;# one minor series&lt;/span&gt;
uv python upgrade           &lt;span class="c"&gt;# every managed version&lt;/span&gt;
uv python install --reinstall   &lt;span class="c"&gt;# reinstall all installed versions&lt;/span&gt;
uv python uninstall 3.12
uv python uninstall --all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After an upgrade, uv keeps the old patch because existing virtual environments may still use it. Environments that follow a minor version are upgraded automatically, but one created with an explicit patch, like &lt;code&gt;uv venv -p 3.10.8&lt;/code&gt;, stays where it is.[2] The mechanism is a minor-version directory, a symlink on Unix or a junction on Windows, that points at a specific patch.[2] If another tool resolves that link and builds a virtual environment from the resolved path, the environment will not auto-upgrade.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Command and flag reference
&lt;/h2&gt;

&lt;p&gt;Bookmark this table. Flags and environment variables are copied from the CLI reference and the environment variable reference.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Useful options&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;uv python list&lt;/code&gt; | List the available Python installations | &lt;code&gt;--only-installed&lt;/code&gt;, &lt;code&gt;--all-versions&lt;/code&gt;, &lt;code&gt;--all-platforms&lt;/code&gt;, &lt;code&gt;--show-urls&lt;/code&gt;, &lt;code&gt;--output-format&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python install&lt;/code&gt; | Download and install Python versions | &lt;code&gt;--default&lt;/code&gt;, &lt;code&gt;--force&lt;/code&gt;, &lt;code&gt;--reinstall&lt;/code&gt;, &lt;code&gt;--upgrade&lt;/code&gt;, &lt;code&gt;--mirror&lt;/code&gt;, &lt;code&gt;--install-dir&lt;/code&gt;, &lt;code&gt;--no-bin&lt;/code&gt;, &lt;code&gt;--no-registry&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python upgrade&lt;/code&gt; | Upgrade installed Python versions | &lt;code&gt;--mirror&lt;/code&gt;, &lt;code&gt;--install-dir&lt;/code&gt;, &lt;code&gt;--reinstall&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python find&lt;/code&gt; | Search for a Python installation | &lt;code&gt;--system&lt;/code&gt;, &lt;code&gt;--show-version&lt;/code&gt;, &lt;code&gt;--no-project&lt;/code&gt;, &lt;code&gt;--script&lt;/code&gt;, &lt;code&gt;--resolve-links&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python pin&lt;/code&gt; | Pin to a specific Python version | &lt;code&gt;--global&lt;/code&gt;, &lt;code&gt;--rm&lt;/code&gt;, &lt;code&gt;--resolved&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python dir&lt;/code&gt; | Show the uv Python installation directory | &lt;code&gt;--bin&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python uninstall&lt;/code&gt; | Uninstall Python versions | &lt;code&gt;--all&lt;/code&gt;, &lt;code&gt;--install-dir&lt;/code&gt;[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;uv python update-shell&lt;/code&gt; | Ensure the Python executable directory is on &lt;code&gt;PATH&lt;/code&gt; | none beyond the global options[3] |&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Environment variable&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON&lt;/code&gt; | Same as &lt;code&gt;--python&lt;/code&gt;; a path makes uv use that interpreter for all operations[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_INSTALL_DIR&lt;/code&gt; | Directory for managed installations[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_BIN_DIR&lt;/code&gt; | Directory for links to installed managed executables[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_INSTALL_BIN&lt;/code&gt; | Whether to install the executable into the bin directory[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_PREFERENCE&lt;/code&gt; | Prefer system or managed Pythons[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_DOWNLOADS&lt;/code&gt; | Whether uv may download Python[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_INSTALL_MIRROR&lt;/code&gt; | Mirror URL replacing the python-build-standalone release host[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_DOWNLOADS_JSON_URL&lt;/code&gt; | Path or URL of a JSON list of installations that overrides the built-in list[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_CACHE_DIR&lt;/code&gt; | Cache directory for archives before installation[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;UV_PYTHON_SEARCH_PATH&lt;/code&gt; | Overrides &lt;code&gt;PATH&lt;/code&gt; for Python discovery[4] |&lt;/p&gt;

&lt;h2&gt;
  
  
  Managed vs system Python
&lt;/h2&gt;

&lt;p&gt;Discovery checks, in order, managed installations in &lt;code&gt;UV_PYTHON_INSTALL_DIR&lt;/code&gt;, then &lt;code&gt;python&lt;/code&gt;, &lt;code&gt;python3&lt;/code&gt; or &lt;code&gt;python3.x&lt;/code&gt; on &lt;code&gt;PATH&lt;/code&gt; (or &lt;code&gt;python.exe&lt;/code&gt; on Windows), then, on Windows only, the registry and Microsoft Store interpreters.[2] Among managed versions uv prefers newer ones first. Among system versions it takes the first compatible one, not the newest.[2] Only if nothing matches does it fall back to a managed download.[2]&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;python-preference&lt;/code&gt; setting controls the order. The default is &lt;code&gt;managed&lt;/code&gt;, which prefers managed Pythons over system ones, but still prefers an existing system Python over downloading a new managed one.[2]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;python-preference&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;th&gt;Flag equivalent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;managed&lt;/code&gt; (default) | Prefer managed; use system before downloading | none |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;only-managed&lt;/code&gt; | Never use system Python | &lt;code&gt;--managed-python&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;system&lt;/code&gt; | Prefer system over managed | none |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;only-system&lt;/code&gt; | Never use managed Python | &lt;code&gt;--no-managed-python&lt;/code&gt; |&lt;/p&gt;

&lt;p&gt;Source for the table: the Python versions concepts page.[2] To stop automatic downloads without changing the preference, set &lt;code&gt;python-downloads&lt;/code&gt; to &lt;code&gt;manual&lt;/code&gt; (the default is &lt;code&gt;automatic&lt;/code&gt;) or pass &lt;code&gt;--no-python-downloads&lt;/code&gt; to any command. In manual mode downloads happen only during &lt;code&gt;uv python install&lt;/code&gt;.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  .python-version and requires-python
&lt;/h2&gt;

&lt;p&gt;Two files steer which interpreter a project uses, and they have different jobs. &lt;code&gt;.python-version&lt;/code&gt; is a request: uv looks for it in the working directory and each parent, then in the user-level configuration directory, and it never searches past a project or workspace boundary except for that user directory. &lt;code&gt;--no-config&lt;/code&gt; turns file discovery off. A plain version number is recommended in it, for interoperability with other tools.[2]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;requires-python&lt;/code&gt; in &lt;code&gt;pyproject.toml&lt;/code&gt; is a constraint. During project commands, uv uses the first Python version compatible with it, unless a version is requested some other way, such as a &lt;code&gt;.python-version&lt;/code&gt; file or &lt;code&gt;--python&lt;/code&gt;.[2] Projects created by &lt;code&gt;uv init&lt;/code&gt; include a &lt;code&gt;.python-version&lt;/code&gt; file next to a &lt;code&gt;requires-python&lt;/code&gt; line, for example &lt;code&gt;requires-python = "&amp;gt;=3.11"&lt;/code&gt;. The &lt;code&gt;--bare&lt;/code&gt; flag skips the pin file unless you add &lt;code&gt;--pin-python&lt;/code&gt;.[5]&lt;/p&gt;

&lt;h2&gt;
  
  
  PATH, --default and executables
&lt;/h2&gt;

&lt;p&gt;On Unix, &lt;code&gt;uv python install 3.12&lt;/code&gt; places a versioned executable such as &lt;code&gt;python3.12&lt;/code&gt; in &lt;code&gt;~/.local/bin&lt;/code&gt;. If that directory is not on &lt;code&gt;PATH&lt;/code&gt;, &lt;code&gt;uv python update-shell&lt;/code&gt; adds it.[2] uv installs only the versioned name by default. To also get &lt;code&gt;python&lt;/code&gt; and &lt;code&gt;python3&lt;/code&gt;, add the experimental &lt;code&gt;--default&lt;/code&gt; option.[1][2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv python install 3.12 --default
python3 --version          &lt;span class="c"&gt;# now resolves to the uv-managed 3.12&lt;/span&gt;

&lt;span class="c"&gt;# an existing non-uv executable needs --force to be replaced&lt;/span&gt;
uv python install 3.12 --default --force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;uv overwrites an existing executable only if uv manages it. A &lt;code&gt;~/.local/bin/python3.12&lt;/code&gt; that uv did not create stays untouched without &lt;code&gt;--force&lt;/code&gt;.[2] Installing 3.12.7, then 3.12.6, then 3.12.8 shows the rule: 3.12.6 does not move the &lt;code&gt;python3.12&lt;/code&gt; link, 3.12.8 does.[2] To skip executables entirely, use &lt;code&gt;--no-bin&lt;/code&gt; or &lt;code&gt;UV_PYTHON_INSTALL_BIN=0&lt;/code&gt;.[3]&lt;/p&gt;

&lt;p&gt;On Windows, uv registers managed installs per PEP 514, so the &lt;code&gt;py&lt;/code&gt; launcher can select them, for example &lt;code&gt;py -V:Astral/CPython3.13.1&lt;/code&gt;. Uninstalling removes the registry entry. &lt;code&gt;--no-registry&lt;/code&gt; or &lt;code&gt;UV_PYTHON_INSTALL_REGISTRY=0&lt;/code&gt; skips registration.[2][3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Offline, mirrors and frozen version lists
&lt;/h2&gt;

&lt;p&gt;The list of downloadable versions is built into the uv binary and frozen per release, so a new Python can require a newer uv.[2][4] For a freshly released version such as 3.15, see our &lt;a href="https://dev.to/blogs/python-3-15-release-october-1-2026-lazy-imports-utf8-default-migration-checklist"&gt;Python 3.15 migration checklist&lt;/a&gt; for what changes in the language itself.&lt;/p&gt;

&lt;p&gt;For restricted networks you have four levers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;UV_PYTHON_INSTALL_MIRROR&lt;/code&gt; (or &lt;code&gt;--mirror&lt;/code&gt;) replaces &lt;code&gt;https://github.com/astral-sh/python-build-standalone/releases/download&lt;/code&gt;. A &lt;code&gt;file://&lt;/code&gt; URL reads distributions from a local directory.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;UV_PYTHON_DOWNLOADS_JSON_URL&lt;/code&gt; (or &lt;code&gt;--python-downloads-json-url&lt;/code&gt;) points uv at your own JSON list of installations, so you can change download URLs or use older or newer Pythons than the built-in list.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;--offline&lt;/code&gt; (env &lt;code&gt;UV_OFFLINE&lt;/code&gt;) is accepted by every &lt;code&gt;uv python&lt;/code&gt; subcommand.[3]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The PyPy, GraalPy and Pyodide mirrors have their own flags: &lt;code&gt;--pypy-mirror&lt;/code&gt;, &lt;code&gt;--graalpy-mirror&lt;/code&gt; and &lt;code&gt;--pyodide-mirror&lt;/code&gt;.[3]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Variants and pre-releases
&lt;/h2&gt;

&lt;p&gt;Pre-releases are not selected by default. uv uses one if no other installation matches the request, and when a pre-release is available and matches, uv will not download a stable version instead.[2] Free-threaded builds exist for CPython 3.13 and later. For 3.13 you must ask for them explicitly with &lt;code&gt;3.13t&lt;/code&gt; or &lt;code&gt;3.13+freethreaded&lt;/code&gt;. From 3.14, uv allows free-threaded interpreters without explicit selection but still prefers the GIL build when installing; &lt;code&gt;+gil&lt;/code&gt; forces the GIL build.[2] Debug builds are requested with &lt;code&gt;3.13d&lt;/code&gt; or &lt;code&gt;3.13+debug&lt;/code&gt;. The docs say they are slower and not appropriate for general use.[2] PyPy lags CPython and currently supports versions only up to 3.11.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expecting &lt;code&gt;python&lt;/code&gt; to change after install.&lt;/strong&gt; Without &lt;code&gt;--default&lt;/code&gt; only &lt;code&gt;python3.12&lt;/code&gt;-style names are created.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Thinking pyenv Pythons are managed.&lt;/strong&gt; uv calls them system Pythons, so &lt;code&gt;--managed-python&lt;/code&gt; ignores them.[2]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expecting the newest system Python.&lt;/strong&gt; uv takes the first compatible one on &lt;code&gt;PATH&lt;/code&gt;.[2]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Trying to install a brand-new release on an old uv.&lt;/strong&gt; The version list is frozen per uv release.[2]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pinning an environment to a patch and expecting upgrades.&lt;/strong&gt; Explicit patch requests like &lt;code&gt;-p 3.10.8&lt;/code&gt; do not auto-upgrade.[2]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using &lt;code&gt;uv python find&lt;/code&gt; in a project folder and getting the venv.&lt;/strong&gt; It includes virtual environments by default, and &lt;code&gt;.venv&lt;/code&gt; or &lt;code&gt;VIRTUAL_ENV&lt;/code&gt; wins over &lt;code&gt;PATH&lt;/code&gt;. Add &lt;code&gt;--system&lt;/code&gt; to skip them.[2]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.astral.sh/uv/guides/install-python/" rel="noopener noreferrer"&gt;Installing and managing Python, uv documentation, Astral (accessed November 30, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.astral.sh/uv/concepts/python-versions/" rel="noopener noreferrer"&gt;Python versions, uv documentation, Astral (accessed November 30, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.astral.sh/uv/reference/cli/" rel="noopener noreferrer"&gt;Commands (uv python), uv documentation, Astral (accessed November 30, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.astral.sh/uv/reference/environment/" rel="noopener noreferrer"&gt;Environment variables, uv documentation, Astral (accessed November 30, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  5. &lt;a href="https://docs.astral.sh/uv/concepts/projects/init/" rel="noopener noreferrer"&gt;Creating projects, uv documentation, Astral (accessed November 30, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/uv-python-install-manage-versions" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>uvpython</category>
      <category>uvpythonpreference</category>
      <category>uvinstall</category>
    </item>
    <item>
      <title>HTTP 429 Too Many Requests: Retry-After and Backoff</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Sun, 29 Nov 2026 01:22:31 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/http-429-too-many-requests-retry-after-and-backoff-5467</link>
      <guid>https://dev.to/akaranjkar08/http-429-too-many-requests-retry-after-and-backoff-5467</guid>
      <description>&lt;p&gt;&lt;strong&gt;HTTP 429 Too Many Requests means the server is rejecting you because you sent too many requests in a given amount of time. The fix is to wait, and to wait at least as long as the Retry-After header says when it is present.&lt;/strong&gt;[1][4] Retry with exponential backoff and jitter, cap the attempts, and retry only requests that are safe to repeat.[2][4] Below: Retry-After parsing, a tested JavaScript retry wrapper, a vendor header table, common mistakes, and how to send a good 429 yourself. For neighboring codes, use the &lt;a href="https://dev.to/tools/http-status-codes"&gt;HTTP status codes reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What HTTP 429 means
&lt;/h2&gt;

&lt;p&gt;RFC 6585 added 429 in April 2012. It says the user has sent too many requests in a given amount of time ("rate limiting"). The response representation SHOULD include details explaining the condition and MAY include a Retry-After header saying how long to wait before making a new request.[1]&lt;/p&gt;

&lt;p&gt;Four details in the RFC matter more than the headline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It does not define how the server identifies the user or counts requests. Limits can be per resource, across the whole server, or across a set of servers, keyed by credentials or a stateful cookie.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Retry-After is optional (MAY), so a 429 can arrive with no wait hint at all and clients need a fallback delay.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responses with 429 MUST NOT be stored by a cache.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Servers are not required to use 429. Under attack, the RFC says it may be more appropriate to drop connections or take other steps, because answering every request with a 429 still consumes resources.[1]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A 429 tells you a limit exists, not what it is. Vendors fill that gap with their own headers and error bodies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retry-After: seconds or a date
&lt;/h2&gt;

&lt;p&gt;RFC 9110 defines the field as &lt;code&gt;Retry-After = HTTP-date / delay-seconds&lt;/code&gt;. A delay-seconds value is a non-negative decimal integer, in seconds. The RFC's two examples are &lt;code&gt;Retry-After: Fri, 31 Dec 1999 23:59:59 GMT&lt;/code&gt; and &lt;code&gt;Retry-After: 120&lt;/code&gt;, where the delay is 2 minutes.[2] RFC 6585's own 429 example sends &lt;code&gt;Retry-After: 3600&lt;/code&gt;.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="nc"&gt;Too&lt;/span&gt; &lt;span class="nc"&gt;Many&lt;/span&gt; &lt;span class="nc"&gt;Requests&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="nc"&gt;Retry&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;After&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Control&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"rate_limited"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"retry_after_seconds"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A client that parses only integers breaks the first time a server sends a date. Handle both, and treat anything unparseable as "no hint". OpenAI's reference retry code does the same: it tries a number first, then a date, then falls back to its own backoff.[4]&lt;/p&gt;

&lt;h3&gt;
  
  
  Retry-After is a floor
&lt;/h3&gt;

&lt;p&gt;OpenAI's guide says to treat the value as a minimum: wait at least that long and add a small random delay so multiple clients do not retry at the same moment.[4] Anthropic's docs agree: wait that many seconds, because earlier retries might fail.[3] Your own backoff schedule decides the wait only when the server gave no hint. When it did, the final delay is the larger of the two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rate limiting algorithms, and what the sources support
&lt;/h2&gt;

&lt;p&gt;Servers decide when to emit a 429 with some counting scheme. The RFC deliberately leaves that open.[1] What the vendor docs confirm:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;th&gt;Source says&lt;/th&gt;
&lt;th&gt;What it means for your client&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Token bucket | Anthropic's API uses the token bucket algorithm: capacity is continuously replenished up to the maximum, rather than reset at fixed intervals[3] | Waiting a few seconds recovers some capacity. There is no top-of-the-minute reset to aim for |&lt;/p&gt;

&lt;p&gt;| Ramp limits | After a sharp usage increase, a 429 can occur even while under the per-minute limits[3][4] | Increase traffic gradually. OpenAI's rule of thumb: past 1 million input tokens per minute, grow by no more than 50% every 15 minutes[4] |&lt;/p&gt;

&lt;p&gt;| Fixed hourly window | GitHub: 60 unauthenticated requests per hour per IP, 5,000 per hour for authenticated users, with &lt;code&gt;x-ratelimit-reset&lt;/code&gt; giving the window reset in UTC epoch seconds[5] | Sleep until the reset time, not for a guessed interval |&lt;/p&gt;

&lt;p&gt;GitHub says its secondary limits can change without notice.[5] Read the response headers instead of hard-coding a vendor's numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exponential backoff with jitter
&lt;/h2&gt;

&lt;p&gt;Exponential backoff means waiting briefly after a failed request, then increasing the delay after each further failure until the request succeeds or hits a retry limit. Adding random jitter keeps clients that failed together from retrying together.[4] OpenAI's guide also warns that unsuccessful requests count toward your per-minute limit, so resending in a tight loop makes things worse.[4]&lt;/p&gt;

&lt;p&gt;The wrapper below uses full jitter (a random delay between zero and an exponentially growing cap), honors Retry-After as a floor, and refuses to retry non-idempotent methods. The max-of-server-delay-and-jittered-backoff step follows the pattern in OpenAI's manual backoff example.[4]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;IDEMPOTENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'HEAD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'OPTIONS'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'PUT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'DELETE'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Retry-After is either delay-seconds or an HTTP-date (RFC 9110, section 10.2.3).&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parseRetryAfter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNaN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sleep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchWithRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;maxAttempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;baseMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;capMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;maxWaitMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;60_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// give up if the server asks for longer than this&lt;/span&gt;
    &lt;span class="n"&gt;retryUnsafe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// set true only if the request carries an idempotency key&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;canRetry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;retryUnsafe&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="no"&gt;IDEMPOTENT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;canRetry&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;maxAttempts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;serverMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parseRetryAfter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'retry-after'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverMs&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;serverMs&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;maxWaitMs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="c1"&gt;// defer, do not hammer&lt;/span&gt;

    &lt;span class="c1"&gt;// Full jitter: random value between 0 and min(cap, base * 2^attempt)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;backoffMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;capMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;baseMs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;// Retry-After is a floor, never something your own backoff may undercut&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;waitMs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverMs&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;backoffMs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;waitMs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Attempts are capped, so the loop cannot spin forever. A server delay longer than &lt;code&gt;maxWaitMs&lt;/code&gt; returns the 429 to the caller instead of sleeping for minutes inside a request handler. OpenAI's guide makes the same call: if a valid server delay exceeds your maximum, stop retrying and defer the request.[4]&lt;/p&gt;

&lt;h3&gt;
  
  
  Run output
&lt;/h3&gt;

&lt;p&gt;The wrapper ran on Node 22 against the local server shown below (bucket of 3 tokens, refilling 1 per second). Six sequential requests with a 100 ms base delay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;req 1: 200 after 19 ms
req 2: 200 after 3 ms
req 3: 200 after 2 ms
req 4: 200 after 1005 ms
req 5: 200 after 1003 ms
req 6: 200 after 1003 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Requests 4 through 6 each received a 429 with &lt;code&gt;Retry-After: 1&lt;/code&gt;, slept slightly over a second, and succeeded on the retry. The 100 ms backoff alone would have retried too early and burned attempts, which is the point of the floor. A POST to the same exhausted bucket came back as a 429 with no retry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Only retry what is safe to repeat
&lt;/h2&gt;

&lt;p&gt;RFC 9110 defines a method as idempotent when multiple identical requests have the same intended effect on the server as a single one. PUT, DELETE and the safe methods are idempotent, and the safe methods defined by the spec are GET, HEAD, OPTIONS and TRACE.[2] It also says a client SHOULD NOT automatically retry a request with a non-idempotent method unless it has some means to know the request semantics are actually idempotent, or some means to detect that the original request was never applied.[2]&lt;/p&gt;

&lt;p&gt;RFC 6585 does not say whether a server did any work before it sent the 429.[1] So a POST that creates an order or sends an email is the case to protect. Retry it only if the API documents a way to deduplicate (for example a client-supplied key), and set &lt;code&gt;retryUnsafe&lt;/code&gt; only then. OpenAI adds two related warnings: do not automatically replay a streaming request after output has been consumed, and do not retry quota or billing errors that need you to act.[4]&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks: common mistakes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mistake&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Fixed 1-second retry, no jitter | Every client that failed together retries together, and the spike repeats | Full jitter plus a growing cap |&lt;/p&gt;

&lt;p&gt;| Ignoring Retry-After | Retries land before the window opens. Failed attempts count against your limit[4] | Delay = max(server hint, jittered backoff) |&lt;/p&gt;

&lt;p&gt;| Parsing Retry-After as an integer only | A date value turns into &lt;code&gt;NaN&lt;/code&gt; and the sleep becomes 0 | Accept delay-seconds and HTTP-date |&lt;/p&gt;

&lt;p&gt;| Retrying a spend or quota 429 | Anthropic's monthly spend-cap 429 has no &lt;code&gt;retry-after&lt;/code&gt; header, and retries, including the SDK's automatic ones, fail until access resumes[3] | Read the error code (&lt;code&gt;enforced_spend_limit_reached&lt;/code&gt;) and stop |&lt;/p&gt;

&lt;p&gt;| Nested retry loops | An SDK that retries inside your own retry loop multiplies requests. OpenAI says to disable SDK retries or account for them[4] | Retry in exactly one layer |&lt;/p&gt;

&lt;p&gt;| No attempt or time budget | One stuck dependency holds threads or workers indefinitely | Cap attempts and total retry time |&lt;/p&gt;

&lt;p&gt;| Hammering while limited | GitHub warns that continuing to make requests while rate limited may result in the banning of your integration[5] | Pause the whole worker pool, not one request |&lt;/p&gt;

&lt;p&gt;Not every 429 carries Retry-After. Anthropic's docs say so directly.[3] GitHub adds a wrinkle: for a secondary limit with no &lt;code&gt;retry-after&lt;/code&gt; and a nonzero &lt;code&gt;x-ratelimit-remaining&lt;/code&gt;, wait at least one minute, then wait exponentially longer between retries and throw after a set number of retries.[5] And GitHub can answer a primary-limit hit with 403 as well as 429, so check headers, not just the status.[5] For a worked failure case in a coding agent, see the &lt;a href="https://dev.to/blogs/codex-429-exceeded-retry-limit-fix"&gt;Codex 429 exceeded retry limit breakdown&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vendor header reference
&lt;/h2&gt;

&lt;p&gt;Bookmark-worthy, because every vendor spells these differently. All rows come from the vendors' own docs.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Header&lt;/th&gt;
&lt;th&gt;Vendor&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;Retry-After&lt;/code&gt; | RFC 9110, OpenAI, Anthropic, GitHub | Seconds to wait (or an HTTP-date per the RFC). Minimum wait, per OpenAI. Not on every 429[2][3][4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;x-ratelimit-remaining&lt;/code&gt; | GitHub | Requests left in the current window. &lt;code&gt;0&lt;/code&gt; on a primary-limit hit[5] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;x-ratelimit-reset&lt;/code&gt; | GitHub | Window reset time in UTC epoch seconds[5] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;x-ratelimit-remaining-requests&lt;/code&gt;, &lt;code&gt;x-ratelimit-remaining-tokens&lt;/code&gt; | OpenAI | Remaining requests or tokens before the limit is exhausted[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;x-ratelimit-reset-requests&lt;/code&gt;, &lt;code&gt;x-ratelimit-reset-tokens&lt;/code&gt; | OpenAI | Time until the limit resets, as a duration such as &lt;code&gt;1s&lt;/code&gt; or &lt;code&gt;6m0s&lt;/code&gt;[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;anthropic-ratelimit-requests-remaining&lt;/code&gt; (and &lt;code&gt;-input-tokens-&lt;/code&gt;, &lt;code&gt;-output-tokens-&lt;/code&gt; variants) | Anthropic | Remaining capacity before being rate limited[3] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;anthropic-ratelimit-requests-reset&lt;/code&gt; (and token variants) | Anthropic | When the limit is fully replenished, in RFC 3339 format[3] |&lt;/p&gt;

&lt;p&gt;Reset values come as epoch seconds on GitHub, durations on OpenAI and timestamps on Anthropic. A shared client needs one parser per vendor. The IETF is working on a common format: draft-ietf-httpapi-ratelimit-headers defines &lt;code&gt;RateLimit-Policy&lt;/code&gt; and &lt;code&gt;RateLimit&lt;/code&gt; header fields. As of November 29, 2026, the datatracker lists it as an active Internet-Draft at revision 12 (last updated November 20, 2026), a working group document with IESG state "I-D Exists".[6] It is not an RFC, so do not depend on those headers being present.&lt;/p&gt;

&lt;h2&gt;
  
  
  429 vs 503
&lt;/h2&gt;

&lt;p&gt;RFC 9110 says 503 Service Unavailable means the server is currently unable to handle the request due to a temporary overload or scheduled maintenance, and it MAY send Retry-After. The same section notes that a server under load does not have to use 503; some simply refuse the connection.[2] The split in practice: 429 is about you (your quota, your rate), and 503 is about the server's capacity.&lt;/p&gt;

&lt;p&gt;OpenAI's current guide shows the split on one API. A &lt;code&gt;429&lt;/code&gt; with code &lt;code&gt;slow_down&lt;/code&gt; means your request rate increased too quickly, while a &lt;code&gt;503&lt;/code&gt; with &lt;code&gt;server_is_overloaded&lt;/code&gt; means the model is temporarily overloaded. For both, follow Retry-After when present.[4] The retry code is the same either way: extend the status check in the wrapper to include 503 if your API behaves this way, and keep the idempotency rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sending a good 429 from your own server
&lt;/h2&gt;

&lt;p&gt;RFC 6585 asks for details in the body and allows a Retry-After header.[1] A useful 429 does four things: it names the limit that was hit, gives a wait time computed from your actual counter, marks the response uncacheable, and uses a stable error code so clients can tell a rate limit from a quota. The server below is a token bucket with capacity 3 and a refill of one token per second, which is what produced the run output above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'node:http'&lt;/span&gt;

&lt;span class="c1"&gt;// Token bucket per client: capacity 3, refills 1 token per second.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;CAPACITY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;REFILL_PER_SEC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;buckets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buckets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;CAPACITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CAPACITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;REFILL_PER_SEC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;
  &lt;span class="n"&gt;buckets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;retryAfter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;REFILL_PER_SEC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// whole seconds, rounded up&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retryAfter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'x-api-key'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteAddress&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'Retry-After'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;retryAfter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'no-store'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'rate_limited'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retry_after_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;retryAfter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeHead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wait time is the time until one full token exists, rounded up to whole seconds, so a client that sleeps exactly that long succeeds. A flat &lt;code&gt;Retry-After: 60&lt;/code&gt; on every rejection makes honest clients wait a minute when the bucket would have refilled in two seconds. Pick the key carefully: the sample uses an API key header, falling back to the remote address, and the RFC leaves that choice to you.[1] Behind a proxy the remote address is the proxy, so every client would share one bucket.&lt;/p&gt;

&lt;p&gt;Because RFC 6585 says 429 responses MUST NOT be stored by a cache, send &lt;code&gt;Cache-Control: no-store&lt;/code&gt; and check that your CDN does not override it.[1] If you are being flooded, answering every request costs resources, and the RFC says dropping connections can be more appropriate.[1]&lt;/p&gt;

&lt;p&gt;Authentication errors look similar in logs but need different handling. The &lt;a href="https://dev.to/blogs/401-vs-403-http-status-codes-explained"&gt;401 vs 403 explainer&lt;/a&gt; covers them, and the &lt;a href="https://dev.to/tools/http-status-codes"&gt;status code lookup&lt;/a&gt; lists the rest of the 4xx family.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc6585.txt" rel="noopener noreferrer"&gt;RFC 6585, Additional HTTP Status Codes, section 4 and section 7.2, IETF, April 2012 (accessed November 29, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9110.txt" rel="noopener noreferrer"&gt;RFC 9110, HTTP Semantics, sections 9.2.1, 9.2.2, 10.2.3 and 15.6.4, IETF, June 2022 (accessed November 29, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://platform.claude.com/docs/en/api/rate-limits" rel="noopener noreferrer"&gt;Rate limits, Claude Platform Docs, Anthropic (accessed November 29, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.openai.com/api/docs/guides/rate-limits" rel="noopener noreferrer"&gt;Rate limits, OpenAI API documentation (accessed November 29, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api" rel="noopener noreferrer"&gt;Rate limits for the REST API, GitHub Docs (accessed November 29, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  6. &lt;a href="https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/" rel="noopener noreferrer"&gt;RateLimit header fields for HTTP, draft-ietf-httpapi-ratelimit-headers-12, IETF Datatracker (accessed November 29, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/http-429-too-many-requests" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>http429</category>
      <category>ratelimiting</category>
      <category>exponentialbackoff</category>
      <category>retryafterheader</category>
    </item>
    <item>
      <title>Zustand Explained: React State Management Guide</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Sat, 28 Nov 2026 01:21:56 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/zustand-explained-react-state-management-guide-28kh</link>
      <guid>https://dev.to/akaranjkar08/zustand-explained-react-state-management-guide-28kh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Zustand is a small, fast state management library for React that gives you a store as a hook: create it with &lt;code&gt;create&lt;/code&gt;, read it with a selector, and skip the providers.&lt;/strong&gt;[1] Install it with &lt;code&gt;npm install zustand&lt;/code&gt;.[1] The latest version on npm at the access date is 5.1.0, it ships with built-in TypeScript types and has zero dependencies, and the repository carries an MIT license.[2][3] The verdict: use it when React state has outgrown &lt;code&gt;useState&lt;/code&gt; and prop drilling, and you want less ceremony than Redux. Five mistakes are covered below, led by selectors that return new objects, mutating state, and sharing one store across Next.js requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Zustand is
&lt;/h2&gt;

&lt;p&gt;The project describes itself as a "small, fast, and scalable bearbones state management solution" with an API based on hooks that is not boilerplatey or opinionated, but has "enough convention to be explicit and flux-like."[1] Its docs say a lot of effort went into common pitfalls, naming the zombie child problem, React concurrency and context loss between mixed renderers.[1]&lt;/p&gt;

&lt;p&gt;The model is simple. The store is a hook, and it can hold primitives, objects and functions. The &lt;code&gt;set&lt;/code&gt; function merges state into the existing state rather than replacing it.[1] Components subscribe through a selector, and a component re-renders when the selected value changes. No provider wraps the app.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Zustand and create a store
&lt;/h2&gt;

&lt;p&gt;Run &lt;code&gt;npm install zustand&lt;/code&gt;, then use the introduction example from the docs: one store with state and actions, and two components that each select only what they need.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useBear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;increasePopulation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bears&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;removeAllBears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;updateBears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newBears&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;newBears&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;BearCounter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bears&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useBear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;bears&lt;/span&gt; &lt;span class="n"&gt;around&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;Controls&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;increasePopulation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useBear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;increasePopulation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that &lt;code&gt;Controls&lt;/code&gt; selects an action, not state. Actions are plain functions stored beside the data, and the docs example selects each one separately from the state it updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update state without mutating it
&lt;/h2&gt;

&lt;p&gt;Calling &lt;code&gt;set&lt;/code&gt; with a partial object shallowly merges it into the store.[5] That covers flat state. Nested state needs more work: the docs call the normal approach copying each level with the spread operator, and admit it is "very long."[5] The npm README states the rule directly: state has to be updated immutably.[2]&lt;/p&gt;

&lt;p&gt;Three escape hatches exist for deep updates, all listed in the docs: Immer, optics-ts and Ramda.[5] The Immer middleware (imported from &lt;code&gt;zustand/middleware/immer&lt;/code&gt;) lets you write mutation-style code inside &lt;code&gt;set&lt;/code&gt;, such as &lt;code&gt;state.bees += by&lt;/code&gt;, while the library produces an immutable update.[2] The middleware docs say you need to install the &lt;code&gt;immer&lt;/code&gt; library separately.[6]&lt;/p&gt;

&lt;p&gt;The README also documents a second argument to &lt;code&gt;set&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; by default. Pass &lt;code&gt;true&lt;/code&gt; and the state is replaced instead of merged, so "be careful not to wipe out parts you rely on, like actions."[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Select state so components re-render less
&lt;/h2&gt;

&lt;p&gt;Zustand compares selector output with strict equality by default, which the README calls efficient for atomic picks.[2] Two separate selectors for two values is the cheapest pattern:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const nuts = useBearStore((state) =&amp;gt; state.nuts)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;const honey = useBearStore((state) =&amp;gt; state.honey)&lt;/code&gt;[2]&lt;/p&gt;

&lt;p&gt;Calling the hook with no selector works, but the README warns that the component then updates on every state change.[2] When one selector must return an object, an array or a derived value, wrap it in &lt;code&gt;useShallow&lt;/code&gt;. The docs explain why: a computed selector causes a re-render if its output changed according to &lt;code&gt;Object.is&lt;/code&gt;, and &lt;code&gt;useShallow&lt;/code&gt; skips the re-render when the new output is shallow equal to the previous one.[4]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;useShallow&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand/react/shallow'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useMeals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;papaBear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'large porridge-pot'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;mamaBear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'middle-size porridge pot'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;littleBear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'A little, small, wee pot'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;BearNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMeals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;useShallow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the docs example, &lt;code&gt;useMeals.setState({ papaBear: 'a large pizza' })&lt;/code&gt; re-renders the component without &lt;code&gt;useShallow&lt;/code&gt; even though the key list is unchanged. With it, the component stays put.[4] The README shows the same wrapper for object and array picks, such as &lt;code&gt;useShallow((state) =&amp;gt; ({ nuts: state.nuts, honey: state.honey }))&lt;/code&gt;.[2]&lt;/p&gt;

&lt;h2&gt;
  
  
  Use TypeScript, persist and devtools
&lt;/h2&gt;

&lt;p&gt;Basic TypeScript use needs one change: write &lt;code&gt;create&amp;lt;State&amp;gt;()(...)&lt;/code&gt; instead of &lt;code&gt;create(...)&lt;/code&gt;.[2] The README's example below also stacks two middlewares. The &lt;code&gt;@redux-devtools/extension&lt;/code&gt; type import is required for devtools typing, and the &lt;code&gt;devtools&lt;/code&gt; docs add that you need to install the &lt;code&gt;@redux-devtools/extension&lt;/code&gt; library to use the middleware from &lt;code&gt;zustand/middleware&lt;/code&gt;.[2][8]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;devtools&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;persist&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand/middleware'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@redux-devtools/extension'&lt;/span&gt; &lt;span class="c1"&gt;// required for devtools typing&lt;/span&gt;

&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;BearState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;
  &lt;span class="n"&gt;increase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useBearStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;devtools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;persist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;increase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;bears&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bears&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'bear-storage'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Middleware&lt;/th&gt;
&lt;th&gt;Import&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Options and notes from the docs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;persist&lt;/code&gt; | &lt;code&gt;zustand/middleware&lt;/code&gt; | Keeps state across page reloads and restarts | &lt;code&gt;name&lt;/code&gt; (required); optional &lt;code&gt;storage&lt;/code&gt;, &lt;code&gt;partialize&lt;/code&gt;, &lt;code&gt;onRehydrateStorage&lt;/code&gt;, &lt;code&gt;version&lt;/code&gt;, &lt;code&gt;migrate&lt;/code&gt;, &lt;code&gt;merge&lt;/code&gt;, &lt;code&gt;skipHydration&lt;/code&gt;[7] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;devtools&lt;/code&gt; | &lt;code&gt;zustand/middleware&lt;/code&gt; | Connects the store to Redux DevTools without Redux | Optional &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;enabled&lt;/code&gt;, &lt;code&gt;anonymousActionType&lt;/code&gt;, &lt;code&gt;store&lt;/code&gt;, &lt;code&gt;actionsDenylist&lt;/code&gt;; &lt;code&gt;enabled&lt;/code&gt; defaults to true in development and false in production[8] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;immer&lt;/code&gt; | &lt;code&gt;zustand/middleware/immer&lt;/code&gt; | Lets you write updates as mutations on a draft | Requires the &lt;code&gt;immer&lt;/code&gt; package[6] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;subscribeWithSelector&lt;/code&gt; | &lt;code&gt;zustand/middleware&lt;/code&gt; | Adds a selector-based &lt;code&gt;subscribe&lt;/code&gt; signature | &lt;code&gt;subscribe(selector, callback, options?: { equalityFn, fireImmediately })&lt;/code&gt;[2] |&lt;/p&gt;

&lt;p&gt;Two persist details matter in production. The default storage is &lt;code&gt;createJSONStorage(() =&amp;gt; localStorage)&lt;/code&gt;, and the getter is evaluated lazily so server rendering does not fail when &lt;code&gt;localStorage&lt;/code&gt; is missing.[7] And &lt;code&gt;partialize&lt;/code&gt; is a function that filters state fields before they are persisted, so you can keep fields you do not want in storage out of it.[7]&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Zustand mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. A selector that returns a new object every time
&lt;/h3&gt;

&lt;p&gt;A selector such as &lt;code&gt;(state) =&amp;gt; ({ nuts: state.nuts, honey: state.honey })&lt;/code&gt; builds a new object on every call, so the &lt;code&gt;Object.is&lt;/code&gt; check sees a change whenever any state changes.[4] Fix it with &lt;code&gt;useShallow&lt;/code&gt;, or select each value separately.[2][4]&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Subscribing to the whole store
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const state = useBearStore()&lt;/code&gt; works, and re-renders the component on every state change.[2] The Next.js guide's example does this with &lt;code&gt;useCounterStore((state) =&amp;gt; state)&lt;/code&gt; to destructure &lt;code&gt;count&lt;/code&gt; and both actions.[9] In a real store with more fields, select only the pieces the component renders.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Mutating state or wiping the store
&lt;/h3&gt;

&lt;p&gt;The docs' deep-state example needs each level copied with the spread operator, because updating nested state has to be done immutably.[5] Writing a mutation such as &lt;code&gt;++state.deep.nested.obj.count&lt;/code&gt; directly in a plain &lt;code&gt;set&lt;/code&gt; skips that, so copy each level or add the Immer middleware.[2][5] And &lt;code&gt;set({}, true)&lt;/code&gt; clears the entire store, actions included.[2]&lt;/p&gt;

&lt;h3&gt;
  
  
  4. One global store shared across Next.js requests
&lt;/h3&gt;

&lt;p&gt;The Zustand store is a global variable, also called module state. A Next.js server can handle several requests at once, so the docs say the store should be created per request and not shared.[9] Their recommendations are "no global stores" and that React Server Components should not read from or write to the store, since they cannot use hooks or context.[9] The README adds that reading or writing state outside components through &lt;code&gt;getState&lt;/code&gt; and &lt;code&gt;setState&lt;/code&gt; is not recommended for state in Server Components, because it can cause unexpected bugs and privacy issues for users.[2]&lt;/p&gt;

&lt;p&gt;The documented pattern is a store factory built on &lt;code&gt;createStore&lt;/code&gt; from &lt;code&gt;zustand/vanilla&lt;/code&gt;, plus a client-side provider that creates the store once with &lt;code&gt;useState&lt;/code&gt;.[9]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/stores/counter-store.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;createStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand/vanilla'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CounterState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CounterActions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;decrementCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
  &lt;span class="n"&gt;incrementCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CounterStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CounterState&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;CounterActions&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;defaultInitState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CounterState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;createCounterStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;initState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CounterState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;defaultInitState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;initState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;decrementCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;incrementCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/providers/counter-store-provider.tsx&lt;/span&gt;
&lt;span class="s1"&gt;'use client'&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;ReactNode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;useStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zustand'&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CounterStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;createCounterStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@/stores/counter-store'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;CounterStoreApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ReturnType&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;CounterStoreContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;CounterStoreProviderProps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ReactNode&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;CounterStoreProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;children&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CounterStoreProviderProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;createCounterStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;useCounterStore&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;CounterStore&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;counterStoreContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CounterStoreContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;counterStoreContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`useCounterStore must be used within CounterStoreProvider`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;useStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counterStoreContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The docs note this guide is due for an update based on a public discussion, so check the page before copying the structure into a production app.[9] Pages Router and App Router use the same pattern. In the App Router, the docs wrap &lt;code&gt;{children}&lt;/code&gt; in the provider inside &lt;code&gt;layout.tsx&lt;/code&gt;, and the example component that calls the hook starts with &lt;code&gt;'use client'&lt;/code&gt;.[9]&lt;/p&gt;

&lt;p&gt;If you are building on a recent Next.js release, the &lt;a href="https://dev.to/blogs/nextjs-16-2-whats-new-april-2026"&gt;Next.js 16.2 changes&lt;/a&gt; are worth reading alongside this setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Persist hydration that does not match the server
&lt;/h3&gt;

&lt;p&gt;Next.js renders twice, once on the server and again on the client, and different output on each side causes hydration errors.[9] React's hydration rules, as quoted in the Zustand docs, list rendering different data on the server and the client, and browser-only API checks like &lt;code&gt;typeof window !== 'undefined'&lt;/code&gt;, among the most common causes. In the worst case, event handlers attach to the wrong elements.[10] A persisted store reads from &lt;code&gt;localStorage&lt;/code&gt;, which exists only in the browser, so reading it during the first render can produce that mismatch (this is the post's inference, not a docs statement).&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;persist&lt;/code&gt; docs give the tool for this: &lt;code&gt;skipHydration&lt;/code&gt; defaults to &lt;code&gt;false&lt;/code&gt;, and when it is &lt;code&gt;true&lt;/code&gt; the middleware does not rehydrate on initialization. You call &lt;code&gt;rehydrate&lt;/code&gt; yourself, which the docs describe as useful for server-side rendering apps.[7]&lt;/p&gt;

&lt;p&gt;The call is &lt;code&gt;positionStore.persist.rehydrate()&lt;/code&gt;. The docs delay it with &lt;code&gt;setTimeout&lt;/code&gt; to demonstrate; in a React app, trigger it after the first client render instead. Two more persist cautions from the docs: &lt;code&gt;createJSONStorage&lt;/code&gt; performs no runtime validation, so corrupt, stale or tampered data is cast straight to your state type, and the docs recommend a custom storage that validates with a schema library such as Zod for production.[7] Use &lt;code&gt;version&lt;/code&gt; with &lt;code&gt;migrate&lt;/code&gt; when the stored shape changes: per the docs, if the stored version does not match, the stored state is not used, and &lt;code&gt;migrate&lt;/code&gt; handles the mismatch.[7] For schema validation on the TypeScript side, see the &lt;a href="https://dev.to/blogs/zod-validation-typescript-api-forms-complete-guide-2026"&gt;Zod validation guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zustand vs Context vs Redux and other libraries
&lt;/h2&gt;

&lt;p&gt;The README gives Zustand's case in short bullets. Against Context: less boilerplate, components render only on changes, and centralized, action-based state. Against Redux: simple and un-opinionated, hooks as the primary way to consume state, no context providers around the app, and transient updates that do not cause renders.[2] The docs comparison page adds the model differences below.[11]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;State model&lt;/th&gt;
&lt;th&gt;Providers needed&lt;/th&gt;
&lt;th&gt;Render optimization&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Zustand | Single store, immutable | No | Manual, with selectors[11] |&lt;/p&gt;

&lt;p&gt;| Redux | Immutable, like Zustand | Yes, context providers | Manual, with selectors[11] |&lt;/p&gt;

&lt;p&gt;| Valtio | Mutable | Not stated | Through property access[11] |&lt;/p&gt;

&lt;p&gt;| Jotai | Primitive atoms composed together | Not stated | Through atom dependency[11] |&lt;/p&gt;

&lt;p&gt;| Recoil | Atoms keyed by string | Yes, context provider | Through atom dependency[11] |&lt;/p&gt;

&lt;p&gt;Read the table as a decision rule. Pick Zustand for a single shared store with explicit actions and no provider tree. Pick an atom library when state is naturally many small independent pieces, and Valtio when you want mutation syntax. The docs frame each as a trade-off, not a ranking.[11]&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;p&gt;Install with &lt;code&gt;npm install zustand&lt;/code&gt;. Create with &lt;code&gt;create&lt;/code&gt;, and with &lt;code&gt;create&amp;lt;State&amp;gt;()(...)&lt;/code&gt; in TypeScript. Select narrowly, and wrap object, array or derived selectors in &lt;code&gt;useShallow&lt;/code&gt; from &lt;code&gt;zustand/react/shallow&lt;/code&gt;. Update immutably, or add the Immer middleware. Persist with &lt;code&gt;partialize&lt;/code&gt; and a &lt;code&gt;version&lt;/code&gt;. In Next.js, create the store per request with &lt;code&gt;createStore&lt;/code&gt; and a provider, and keep Server Components away from it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/learn/getting-started/introduction" rel="noopener noreferrer"&gt;Introduction, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.npmjs.com/package/zustand" rel="noopener noreferrer"&gt;zustand, npm package page and README, version 5.1.0 (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/pmndrs/zustand" rel="noopener noreferrer"&gt;pmndrs/zustand, GitHub repository (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/learn/guides/prevent-rerenders-with-use-shallow" rel="noopener noreferrer"&gt;Prevent rerenders with useShallow, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/learn/guides/updating-state" rel="noopener noreferrer"&gt;Updating state, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/reference/middlewares/immer" rel="noopener noreferrer"&gt;immer middleware, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/reference/middlewares/persist" rel="noopener noreferrer"&gt;persist middleware, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/reference/middlewares/devtools" rel="noopener noreferrer"&gt;devtools middleware, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/learn/guides/nextjs" rel="noopener noreferrer"&gt;Setup with Next.js, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zustand.docs.pmnd.rs/learn/guides/ssr-and-hydration" rel="noopener noreferrer"&gt;SSR and Hydration, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  11. &lt;a href="https://zustand.docs.pmnd.rs/learn/getting-started/comparison" rel="noopener noreferrer"&gt;Comparison, Zustand Docs (accessed November 28, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/zustand-react-state-guide" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>zustand</category>
      <category>zustandreact</category>
      <category>zustandtutorial</category>
      <category>zustandvs</category>
    </item>
    <item>
      <title>Markdown Cheat Sheet: CommonMark and GFM Syntax</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Fri, 27 Nov 2026 01:30:19 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/markdown-cheat-sheet-commonmark-and-gfm-syntax-5b4g</link>
      <guid>https://dev.to/akaranjkar08/markdown-cheat-sheet-commonmark-and-gfm-syntax-5b4g</guid>
      <description>&lt;p&gt;&lt;strong&gt;This Markdown cheat sheet lists the syntax that converts plain text to HTML: &lt;code&gt;#&lt;/code&gt; for headings, &lt;code&gt;*&lt;/code&gt; or &lt;code&gt;_&lt;/code&gt; for emphasis, &lt;code&gt;-&lt;/code&gt; for lists, backticks for code, and &lt;code&gt;[text](url)&lt;/code&gt; for links.&lt;/strong&gt; CommonMark is the baseline specification, currently version 0.31.2, dated 2024-01-28.[1] GitHub Flavored Markdown (GFM) builds on it and adds tables, task lists, strikethrough and extended autolinks.[2] Below: a bookmarkable reference table, the exact spec output for each pattern, GFM-only features, and the mistakes that break rendering. To try any snippet, paste it into the &lt;a href="https://dev.to/tools/markdown-editor"&gt;free Markdown editor&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cheat sheet at a glance
&lt;/h2&gt;

&lt;p&gt;Every row below comes from the CommonMark spec, the GFM spec or GitHub's formatting docs. The last column says which one, so you know whether a pattern works everywhere or only on GFM renderers.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Element&lt;/th&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Heading | &lt;code&gt;# foo&lt;/code&gt; through &lt;code&gt;###### foo&lt;/code&gt; | CommonMark, Example 62 |&lt;/p&gt;

&lt;p&gt;| Italic | &lt;code&gt;*text*&lt;/code&gt; or &lt;code&gt;_text_&lt;/code&gt; | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Bold | &lt;code&gt;**text**&lt;/code&gt; or &lt;code&gt;__text__&lt;/code&gt; | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Strikethrough | &lt;code&gt;~~text~~&lt;/code&gt; or &lt;code&gt;~text~&lt;/code&gt; | GFM, Example 491 |&lt;/p&gt;

&lt;p&gt;| Block quote | &lt;code&gt;&amp;gt; text&lt;/code&gt; | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Inline code | &lt;code&gt;code&lt;/code&gt; | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Fenced code block | Three backticks or three tildes, plus an optional language | CommonMark, Examples 142, 143 |&lt;/p&gt;

&lt;p&gt;| Link | &lt;code&gt;[text](/uri "title")&lt;/code&gt; | CommonMark, Example 482 |&lt;/p&gt;

&lt;p&gt;| Image | &lt;code&gt;![alt](/url "title")&lt;/code&gt; | CommonMark, Example 572 |&lt;/p&gt;

&lt;p&gt;| Bullet list | &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt; before each item | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Numbered list | &lt;code&gt;1.&lt;/code&gt; before each item | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Task list | &lt;code&gt;- [ ] todo&lt;/code&gt; and &lt;code&gt;- [x] done&lt;/code&gt; | GFM, Example 279 |&lt;/p&gt;

&lt;p&gt;| Horizontal rule | &lt;code&gt;***&lt;/code&gt;, &lt;code&gt;---&lt;/code&gt; or &lt;code&gt;___&lt;/code&gt; | CommonMark, Example 43 |&lt;/p&gt;

&lt;p&gt;| Hard line break | Two or more trailing spaces, or a trailing backslash | CommonMark, Example 633 |&lt;/p&gt;

&lt;p&gt;| Escape a character | &lt;code&gt;\*&lt;/code&gt; before the Markdown character | CommonMark, Example 12; GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Footnote | &lt;code&gt;[^1]&lt;/code&gt; and &lt;code&gt;[^1]: text&lt;/code&gt; | GitHub Docs |&lt;/p&gt;

&lt;p&gt;| Hidden comment | &lt;code&gt;&amp;lt;!-- text --&amp;gt;&lt;/code&gt; | GitHub Docs |&lt;/p&gt;

&lt;p&gt;One caution on the "Source" column. GitHub Docs describe how github.com renders Markdown. They are not a spec for every renderer, so footnotes and alerts below are GitHub behavior, not CommonMark.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Headings and paragraphs
&lt;/h2&gt;

&lt;p&gt;A heading is one to six &lt;code&gt;#&lt;/code&gt; characters followed by text. The number of hashes sets the level.[3] The spec's Example 62 maps &lt;code&gt;# foo&lt;/code&gt; to &lt;code&gt;&amp;lt;h1&amp;gt;foo&amp;lt;/h1&amp;gt;&lt;/code&gt;, and so on down to &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;.[1]&lt;/p&gt;

&lt;p&gt;Two edge cases catch people. Seven hashes is not a heading: Example 63, &lt;code&gt;####### foo&lt;/code&gt;, renders as the paragraph &lt;code&gt;&amp;lt;p&amp;gt;####### foo&amp;lt;/p&amp;gt;&lt;/code&gt;.[1] And a hash with no space after it is not a heading either. Example 64 shows &lt;code&gt;#5 bolt&lt;/code&gt; and &lt;code&gt;#hashtag&lt;/code&gt; both coming out as plain paragraphs.[1] That second rule matters on any platform where you paste a line starting with a hashtag.&lt;/p&gt;

&lt;h2&gt;
  
  
  Emphasis: bold, italic and strikethrough
&lt;/h2&gt;

&lt;p&gt;GitHub's docs give two spellings for each: italic is &lt;code&gt;*text*&lt;/code&gt; or &lt;code&gt;_text_&lt;/code&gt;, and bold is &lt;code&gt;**text**&lt;/code&gt; or &lt;code&gt;__text__&lt;/code&gt;.[3] They are not fully interchangeable, though. In CommonMark, &lt;code&gt;foo*bar*&lt;/code&gt; renders as &lt;code&gt;foo&amp;lt;em&amp;gt;bar&amp;lt;/em&amp;gt;&lt;/code&gt; (Example 355), while &lt;code&gt;foo_bar_&lt;/code&gt; stays literal text, &lt;code&gt;&amp;lt;p&amp;gt;foo_bar_&amp;lt;/p&amp;gt;&lt;/code&gt; (Example 360).[1] Underscores do not start emphasis in the middle of a word. If you need italics inside a word, use asterisks. It also means &lt;code&gt;snake_case_names&lt;/code&gt; are safe from accidental italics.&lt;/p&gt;

&lt;p&gt;Strikethrough is a GFM addition. The spec defines it as text wrapped in a matching pair of one or two tildes.[2] Example 491 takes &lt;code&gt;~~Hi~~ Hello, ~there~ world!&lt;/code&gt; to &lt;code&gt;&amp;lt;del&amp;gt;Hi&amp;lt;/del&amp;gt; Hello, &amp;lt;del&amp;gt;there&amp;lt;/del&amp;gt; world!&lt;/code&gt; inside a paragraph.[2] A renderer that implements only core CommonMark will show the tildes as literal characters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lists, nesting and task lists
&lt;/h2&gt;

&lt;p&gt;Bullet lists start each item with &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt;. Numbered lists start with a number and a period. A nested list is indented under its parent item.[3] GitHub's own nested example indents each level three spaces:[3]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;1. First list item
   &lt;span class="k"&gt;- &lt;/span&gt;First nested list item
     &lt;span class="k"&gt;- &lt;/span&gt;Second nested list item
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two list rules produce surprises. First, the bullet character is part of the list's identity: Example 301, &lt;code&gt;- foo&lt;/code&gt;, &lt;code&gt;- bar&lt;/code&gt;, &lt;code&gt;+ baz&lt;/code&gt;, renders as two separate &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; lists, one holding foo and bar and another holding baz.[1] Pick one marker per list and keep it. Second, the first number in an ordered list is meaningful. Example 267, &lt;code&gt;0. ok&lt;/code&gt;, renders as &lt;code&gt;&amp;lt;ol start="0"&amp;gt;&lt;/code&gt;.[1]&lt;/p&gt;

&lt;p&gt;Task lists are a GFM extension. A task list item is a list item whose first paragraph begins with &lt;code&gt;[ ]&lt;/code&gt; for unchecked or &lt;code&gt;[x]&lt;/code&gt; for checked, followed by whitespace. The spec says the character between the brackets can be a space or an &lt;code&gt;x&lt;/code&gt;, in lowercase or uppercase.[2] Example 279 renders &lt;code&gt;- [ ] foo&lt;/code&gt; and &lt;code&gt;- [x] bar&lt;/code&gt; as list items containing a checkbox &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;, with the second one marked &lt;code&gt;checked=""&lt;/code&gt;.[2]&lt;/p&gt;

&lt;p&gt;The spec also notes that it does not define how the checkboxes are interacted with, so whether a rendered box is clickable depends on the renderer.[2] GitHub's docs add one gotcha: if a task item's description begins with a parenthesis, escape it, as in &lt;code&gt;- [ ] \(Optional) Open a followup issue&lt;/code&gt;.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Code: inline spans and fenced blocks
&lt;/h2&gt;

&lt;p&gt;Single backticks mark code inside a sentence, and the text inside is not formatted.[3] For a block, GitHub's docs say to use triple backticks.[3] The CommonMark spec also allows tildes as the fence, and the text after the opening fence is the info string. Examples 142 and 143 both turn an info string beginning with &lt;code&gt;ruby&lt;/code&gt; into &lt;code&gt;&amp;lt;pre&amp;gt;&amp;lt;code class="language-ruby"&amp;gt;&lt;/code&gt;.[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
ruby&lt;br&gt;
def foo(x)&lt;br&gt;
  return 3&lt;br&gt;
end&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
markdown&lt;/p&gt;

&lt;p&gt;The spec only defines the class name in the output. None of the three sources opened for this guide covers a literal triple backtick inside a fence, so this guide leaves it out. Check your renderer's docs for that case.&lt;/p&gt;
&lt;h2&gt;
  
  
  Links, images and autolinks
&lt;/h2&gt;

&lt;p&gt;A link is link text in square brackets followed by the destination in parentheses. GitHub's example is &lt;code&gt;[GitHub Pages](https://pages.github.com/)&lt;/code&gt;.[3] An optional quoted title follows the URL: Example 482, &lt;code&gt;[link](/uri "title")&lt;/code&gt;, renders as &lt;code&gt;&amp;lt;a href="/uri" title="title"&amp;gt;link&amp;lt;/a&amp;gt;&lt;/code&gt;.[1] An image is the same syntax with a leading &lt;code&gt;!&lt;/code&gt;, and the bracketed text becomes the alt text.[3] Example 572 renders &lt;code&gt;![foo](/url "title")&lt;/code&gt; as &lt;code&gt;&amp;lt;img src="/url" alt="foo" title="title" /&amp;gt;&lt;/code&gt;.[1] Write real alt text, since GitHub describes it as a short text equivalent of the information in the image.[3]&lt;/p&gt;

&lt;p&gt;GFM adds autolinks that need no angle brackets. Three kinds are defined, and each is recognized only at the start of a line, after whitespace, or after one of the characters &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt;, &lt;code&gt;~&lt;/code&gt; and &lt;code&gt;(&lt;/code&gt;.[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;www.commonmark.org
http://commonmark.org
foo@bar.baz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;p&gt;Per the spec, the first becomes a link to &lt;code&gt;http://www.commonmark.org&lt;/code&gt; because the scheme &lt;code&gt;http&lt;/code&gt; is inserted automatically (Example 622). The second is an extended URL autolink for &lt;code&gt;http://&lt;/code&gt; or &lt;code&gt;https://&lt;/code&gt; followed by a valid domain (Example 629). The third becomes a &lt;code&gt;mailto:&lt;/code&gt; link, with the scheme added automatically (Example 630).[2]&lt;/p&gt;

&lt;p&gt;Trailing punctuation is handled for you. The characters &lt;code&gt;?&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;, &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;,&lt;/code&gt;, &lt;code&gt;:&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt; at the end are not part of the link, though they may appear inside it. So &lt;code&gt;Visit www.commonmark.org.&lt;/code&gt; links the domain and leaves the period outside (Example 624).[2] Unmatched closing parentheses are also left out: &lt;code&gt;www.google.com/search?q=Markup+(business)))&lt;/code&gt; links through the first closing parenthesis and leaves the other two outside the link (Example 625).[2]&lt;/p&gt;
&lt;h2&gt;
  
  
  Line breaks, rules and escapes
&lt;/h2&gt;

&lt;p&gt;A hard line break is a line ending preceded by two or more spaces, rendered as &lt;code&gt;&amp;lt;br /&amp;gt;&lt;/code&gt; (Example 633).[1] The spec also provides a backslash form, so a backslash at the end of the line gives the same &lt;code&gt;&amp;lt;br /&amp;gt;&lt;/code&gt; without invisible trailing spaces.[1] Prefer the backslash. Trailing spaces are easy to lose in an editor that trims whitespace on save.&lt;/p&gt;

&lt;p&gt;A horizontal rule is three of &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;_&lt;/code&gt; on a line. Example 43 renders &lt;code&gt;***&lt;/code&gt;, &lt;code&gt;---&lt;/code&gt; and &lt;code&gt;___&lt;/code&gt; each as &lt;code&gt;&amp;lt;hr /&amp;gt;&lt;/code&gt;.[1]&lt;/p&gt;

&lt;p&gt;To show a Markdown character literally, put a backslash before it. GitHub's example is &lt;code&gt;Let's rename \*our-new-project\* to \*our-old-project\*.&lt;/code&gt;, which stops the asterisks from creating emphasis.[3] Example 12 in the spec escapes the full run of ASCII punctuation characters, and the HTML output shows each one as plain text with the backslash gone.[1]&lt;/p&gt;
&lt;h2&gt;
  
  
  Tables: one line here, a full guide elsewhere
&lt;/h2&gt;

&lt;p&gt;GFM enables a &lt;code&gt;table&lt;/code&gt; extension, which adds one more leaf block type.[2] Tables are an extension, not part of core CommonMark, so a renderer without that extension may not turn pipe-delimited source into a table. Alignment colons, pipe escaping and the failure cases fill a full guide of their own: see &lt;a href="https://dev.to/blogs/markdown-table-syntax-guide"&gt;the Markdown table syntax guide&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  GitHub-specific extras
&lt;/h2&gt;

&lt;p&gt;These three are documented by GitHub, not by the CommonMark spec, so treat them as GitHub behavior unless your renderer says otherwise.[3]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Here is a simple footnote[^1].

&amp;gt; [!NOTE]
&amp;gt; Useful information that users should know, even when skimming content.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Footnotes use a &lt;code&gt;[^1]&lt;/code&gt; reference and a &lt;code&gt;[^1]:&lt;/code&gt; definition. An HTML comment hides content from the rendered output. Alerts are a special blockquote line naming the type, followed by the alert text in a standard blockquote. GitHub lists five types: NOTE, TIP, IMPORTANT, WARNING and CAUTION.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  Raw HTML and the tag filter
&lt;/h2&gt;

&lt;p&gt;GFM also enables a &lt;code&gt;tagfilter&lt;/code&gt; extension. When it is on, these nine HTML tags are filtered in the rendered output: &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;xmp&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;noembed&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;noframes&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;plaintext&amp;gt;&lt;/code&gt;.[2] In Example 657 the filtered tags come out as escaped text, &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;, while a &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; and an &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt; in the same line pass through untouched.[2] So with the tagfilter on, an iframe or script tag pasted into a GFM document comes out as escaped text. Do not rely on raw HTML for layout in a document that may be rendered by a GFM-compatible tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes and what causes them
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Cause&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Heading shows as plain text with hashes | No space after &lt;code&gt;#&lt;/code&gt;, or seven or more hashes | Use one to six hashes and a space | Examples 63, 64 |&lt;/p&gt;

&lt;p&gt;| Italics missing inside a word | Underscores do not open emphasis mid-word | Use asterisks | Examples 355, 360 |&lt;/p&gt;

&lt;p&gt;| One list splits into two | The bullet character changed partway | Keep one marker per list | Example 301 |&lt;/p&gt;

&lt;p&gt;| Numbered list starts at 0 or another number | The first number sets the start value | Begin with the number you want shown first | Example 267 |&lt;/p&gt;

&lt;p&gt;| Strikethrough shows tildes | The renderer has no GFM strikethrough | Check the renderer's flavor | GFM spec |&lt;/p&gt;

&lt;p&gt;| Checkbox shows as &lt;code&gt;[ ]&lt;/code&gt; text | The renderer has no task list extension | Check the renderer's flavor | GFM spec |&lt;/p&gt;

&lt;p&gt;| Line break disappears | Trailing spaces trimmed by the editor | End the line with a backslash | Example 633 |&lt;/p&gt;

&lt;p&gt;| Asterisks vanish and text turns italic | Unescaped Markdown character | Put a backslash before it | Example 12 |&lt;/p&gt;

&lt;h2&gt;
  
  
  Check which flavor your renderer runs
&lt;/h2&gt;

&lt;p&gt;The biggest source of "Markdown that doesn't work" is flavor, not syntax. Tables, task lists, strikethrough and bare-URL autolinks are GFM extensions, so each depends on the renderer enabling them.[2] Footnotes and alerts, as documented here, are GitHub features.[3] Versions differ too: the CommonMark page opened for this guide is 0.31.2 (2024-01-28), while the GFM spec page is version 0.29-gfm (2019-04-06).[1][2] This guide does not map which rules changed between those two versions, so verify any edge case in the renderer you publish to.&lt;/p&gt;

&lt;p&gt;The quickest check is to paste a mixed sample into the &lt;a href="https://dev.to/tools/markdown-editor"&gt;Markdown editor&lt;/a&gt; and read the preview. The editor's parser is not verified against the spec examples cited here (unconfirmed), so treat its preview as a drafting aid and confirm the final output where the document will live.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;p&gt;Headings take one to six hashes plus a space. Italics use one asterisk or underscore, bold uses two, and strikethrough uses one or two tildes on GFM. Lists use &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt; and keep a single marker per list. Code uses single backticks inline and triple backticks or tildes for a block. A link is &lt;code&gt;[text](url)&lt;/code&gt; and an image adds a leading &lt;code&gt;!&lt;/code&gt;. Task lists are &lt;code&gt;- [ ]&lt;/code&gt; and &lt;code&gt;- [x]&lt;/code&gt;. A backslash escapes any Markdown character and a trailing backslash breaks a line. Core CommonMark is the safe baseline. Everything else depends on your renderer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://spec.commonmark.org/0.31.2/" rel="noopener noreferrer"&gt;CommonMark Spec, version 0.31.2, 2024-01-28 (accessed November 27, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.github.com/gfm/" rel="noopener noreferrer"&gt;GitHub Flavored Markdown Spec, version 0.29-gfm, 2019-04-06 (accessed November 27, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. &lt;a href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax" rel="noopener noreferrer"&gt;Basic writing and formatting syntax, GitHub Docs (accessed November 27, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/markdown-cheat-sheet-syntax-reference" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>markdowncheat</category>
      <category>markdownsyntax</category>
      <category>commonmarksyntax</category>
      <category>gfmsyntax</category>
    </item>
    <item>
      <title>Subnet Mask Cheat Sheet: /8 to /32 CIDR Table</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Thu, 26 Nov 2026 01:24:48 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/subnet-mask-cheat-sheet-8-to-32-cidr-table-2d57</link>
      <guid>https://dev.to/akaranjkar08/subnet-mask-cheat-sheet-8-to-32-cidr-table-2d57</guid>
      <description>&lt;p&gt;&lt;strong&gt;A subnet mask is a 32-bit value whose one-bits mark the network part of an IPv4 address and whose zero-bits mark the host part.&lt;/strong&gt; This subnet mask cheat sheet gives you the whole /8 to /32 CIDR table in one place. The rule behind it: a /N prefix means the first N bits are the network, and the block holds 2^(32-N) addresses. Subtract two for the network and broadcast addresses to get usable hosts, except on /31 and /32. If you only need one answer, drop an address into the &lt;a href="https://dev.to/tools/subnet-calculator"&gt;subnet calculator&lt;/a&gt;. If you want to understand the answer, read on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a subnet mask does
&lt;/h2&gt;

&lt;p&gt;RFC 950 (August 1985) specified the address mask as the way a host learns where the network ends. It describes the mask as a bit-mask with bits set in the fields for the IP network number, plus extra bits for the subnet number field.[1] RFC 4632 later wrote the same idea as a prefix: a 4-octet address, a slash, and a decimal value between 0 and 32 that counts the significant bits.[2] Its example: 172.16.0.0/16 means the mask has 16 one-bits followed by 16 zero-bits, which is 255.255.0.0.[2]&lt;/p&gt;

&lt;p&gt;So &lt;code&gt;/24&lt;/code&gt; and &lt;code&gt;255.255.255.0&lt;/code&gt; are the same fact written two ways. CIDR notation is the shorter way to write it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The CIDR table: /8 to /32
&lt;/h2&gt;

&lt;p&gt;Bookmark this one. The address counts for each prefix match the table in RFC 4632;[2] the dotted and wildcard masks and the usable-host column are computed from the prefix with Python's &lt;code&gt;ipaddress&lt;/code&gt; module. The wildcard mask is simply the mask with every bit flipped.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CIDR&lt;/th&gt;
&lt;th&gt;Subnet mask&lt;/th&gt;
&lt;th&gt;Wildcard mask&lt;/th&gt;
&lt;th&gt;Total addresses&lt;/th&gt;
&lt;th&gt;Usable hosts&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 |&lt;/p&gt;

&lt;p&gt;| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 |&lt;/p&gt;

&lt;p&gt;| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 |&lt;/p&gt;

&lt;p&gt;| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 |&lt;/p&gt;

&lt;p&gt;| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 |&lt;/p&gt;

&lt;p&gt;| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 |&lt;/p&gt;

&lt;p&gt;| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 |&lt;/p&gt;

&lt;p&gt;| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 |&lt;/p&gt;

&lt;p&gt;| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 |&lt;/p&gt;

&lt;p&gt;| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 |&lt;/p&gt;

&lt;p&gt;| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 |&lt;/p&gt;

&lt;p&gt;| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 |&lt;/p&gt;

&lt;p&gt;| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 |&lt;/p&gt;

&lt;p&gt;| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 |&lt;/p&gt;

&lt;p&gt;| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 |&lt;/p&gt;

&lt;p&gt;| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 |&lt;/p&gt;

&lt;p&gt;| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 |&lt;/p&gt;

&lt;p&gt;| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 |&lt;/p&gt;

&lt;p&gt;| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 |&lt;/p&gt;

&lt;p&gt;| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 |&lt;/p&gt;

&lt;p&gt;| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 |&lt;/p&gt;

&lt;p&gt;| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 |&lt;/p&gt;

&lt;p&gt;| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 |&lt;/p&gt;

&lt;p&gt;| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 on point-to-point links[4] |&lt;/p&gt;

&lt;p&gt;| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 (a host route)[2] |&lt;/p&gt;

&lt;p&gt;The pattern is worth memorizing, because it replaces the table. In the interesting octet, the mask value is 256 minus the block size: a /26 has blocks of 64, so the last octet is 256 - 64 = 192. Block starts are multiples of the block size, so /26 networks start at .0, .64, .128 and .192. RFC 4632 says the same thing in its own words: prefixes describe any power-of-two-sized block of addresses.[2] It also notes that, as of its 2006 text, prefixes shorter than /8 had not been allocated or assigned.[2] This table starts at /8 for that reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worked example 1: network, broadcast and host range
&lt;/h2&gt;

&lt;p&gt;Take 192.168.10.77 with mask 255.255.255.192 (/26). The mask has 26 one-bits, so the network address is the IP with the 6 host bits zeroed. Write both in binary and AND them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;192.168.10.77   11000000.10101000.00001010.01001101
255.255.255.192 11111111.11111111.11111111.11000000
AND result      11000000.10101000.00001010.01000000  = 192.168.10.64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Last octet: 77 AND 192 = 64. The block size is 64, so the broadcast address is the last address before the next block, 64 + 63 = 127. I checked every value below with Python's &lt;code&gt;ipaddress&lt;/code&gt; module:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Network address | 192.168.10.64 |&lt;/p&gt;

&lt;p&gt;| Broadcast address | 192.168.10.127 |&lt;/p&gt;

&lt;p&gt;| First usable host | 192.168.10.65 |&lt;/p&gt;

&lt;p&gt;| Last usable host | 192.168.10.126 |&lt;/p&gt;

&lt;p&gt;| Usable hosts | 62 |&lt;/p&gt;

&lt;p&gt;Why two addresses are lost: on an ordinary subnet the all-zeros host value names the network and the all-ones value is the broadcast. RFC 3021 states this directly when it explains the /30: four addresses per link, which means two host addresses, one all-zeros network and one all-ones broadcast.[4] The usable-hosts column subtracts those same two addresses for every prefix from /8 through /30.&lt;/p&gt;

&lt;p&gt;Skip the binary for a one-off check and use the &lt;a href="https://dev.to/tools/subnet-calculator"&gt;subnet calculator&lt;/a&gt; with 192.168.10.77/26. It should return the same five values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worked example 2: split a /24 into four subnets
&lt;/h2&gt;

&lt;p&gt;Four subnets need 2 extra bits (2^2 = 4), so 24 + 2 = /26. Each block holds 64 addresses. Python confirms the split of 192.168.10.0/24:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ipaddress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ip_network&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'192.168.10.0/24'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subnets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_prefix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;broadcast_address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output, reformatted as a table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Subnet&lt;/th&gt;
&lt;th&gt;Usable range&lt;/th&gt;
&lt;th&gt;Broadcast&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| 192.168.10.0/26 | 192.168.10.1 to 192.168.10.62 | 192.168.10.63 |&lt;/p&gt;

&lt;p&gt;| 192.168.10.64/26 | 192.168.10.65 to 192.168.10.126 | 192.168.10.127 |&lt;/p&gt;

&lt;p&gt;| 192.168.10.128/26 | 192.168.10.129 to 192.168.10.190 | 192.168.10.191 |&lt;/p&gt;

&lt;p&gt;| 192.168.10.192/26 | 192.168.10.193 to 192.168.10.254 | 192.168.10.255 |&lt;/p&gt;

&lt;p&gt;Splitting costs hosts. One /24 gave 254 usable addresses; four /26 subnets give 4 x 62 = 248. The six missing addresses are the extra network and broadcast pairs. Splitting the same /24 into eight /27 subnets leaves 8 x 30 = 240.&lt;/p&gt;

&lt;p&gt;A 1985 caveat on this split. RFC 950 says the values of all zeros and all ones in the subnet field should not be assigned to actual subnets; in its 6-bit example, the subnet field may have any value except 0 and 63.[1] By that original rule, the first and last /26 above (192.168.10.0/26 and 192.168.10.192/26) would be off limits. This post does not cover whether later standards relax that rule, so treat it as unverified here. Check the documentation of your router or cloud provider before you use the first and last subnet of a split.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worked example 3: how the AND decides local vs gateway
&lt;/h2&gt;

&lt;p&gt;RFC 950 describes the test every host runs before it sends a packet. If the destination ANDed with the host's own mask equals the host's own address ANDed with the same mask, the datagram goes directly to the destination on the local network. Otherwise it goes to a gateway.[1] The RFC's version, as pseudocode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IF bitwise_and(dg.ip_dest, my_ip_mask)
                          = bitwise_and(my_ip_addr, my_ip_mask)
    THEN
        send_dg_locally(dg, dg.ip_dest)
    ELSE
        send_dg_locally(dg,
               gateway_to(bitwise_and(dg.ip_dest, my_ip_mask)))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run that test for a host at 10.1.1.20 with mask 255.255.255.0. I ran the AND check in Python for these cases:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Destination&lt;/th&gt;
&lt;th&gt;Mask on the host&lt;/th&gt;
&lt;th&gt;Same network?&lt;/th&gt;
&lt;th&gt;Packet goes to&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| 10.1.1.200 | 255.255.255.0 | Yes | The destination directly |&lt;/p&gt;

&lt;p&gt;| 10.1.2.5 | 255.255.255.0 | No | The default gateway |&lt;/p&gt;

&lt;p&gt;| 10.1.2.5 | 255.255.254.0 | No | The default gateway |&lt;/p&gt;

&lt;p&gt;The mask on the sending host alone decides the answer. Nothing asks the destination what it thinks its mask is. That one-sided decision is why a wrong mask on a single machine causes the strange, half-working failures in the mistakes table below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Edge cases: /31, /32 and special addresses
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;/31 on point-to-point links.&lt;/strong&gt; A /31 has one host bit, so only two addresses exist: the all-zeros and all-ones host values. RFC 3021 (December 2000) says that on a point-to-point link with a 31-bit mask, these two addresses MUST be interpreted as host addresses.[4] The saving is real: each link uses two addresses instead of four, so 500 links save 1,000 addresses.[4] There is no directed broadcast on such a link, and the limited broadcast must be used for broadcast traffic.[4] The catch: RFC 3021 warns that a point-to-point link where only one end supports 31-bit prefixes may not operate correctly.[4] Configure both ends or neither. Python agrees with the RFC on the arithmetic: 10.0.0.0/31 contains 10.0.0.0 and 10.0.0.1, and both come back as hosts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/32 host route.&lt;/strong&gt; All 32 bits are network, so the prefix names one address. RFC 4632 labels n.n.n.n/32 a "host route".[2]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/0 default route.&lt;/strong&gt; The other end of the scale. RFC 4632 lists 0.0.0.0/0 as the "default route", a block of 4,294,967,296 addresses, which is the entire IPv4 space.[2]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private ranges.&lt;/strong&gt; RFC 1918 (February 1996) reserves three blocks for private internets:[3]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Block&lt;/th&gt;
&lt;th&gt;Range&lt;/th&gt;
&lt;th&gt;Prefix&lt;/th&gt;
&lt;th&gt;Addresses&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| 10.0.0.0 | 10.0.0.0 to 10.255.255.255 | 10/8 | 16,777,216 |&lt;/p&gt;

&lt;p&gt;| 172.16.0.0 | 172.16.0.0 to 172.31.255.255 | 172.16/12 | 1,048,576 |&lt;/p&gt;

&lt;p&gt;| 192.168.0.0 | 192.168.0.0 to 192.168.255.255 | 192.168/16 | 65,536 |&lt;/p&gt;

&lt;p&gt;The address counts are computed. The middle row trips people up: 172.16.0.0/12 runs through 172.31.255.255, so 172.32.x.x is not private. RFC 1918 also says that packets with private source or destination addresses should not be forwarded across inter-enterprise links, and that ISPs are expected to filter routing information about private networks.[3] It recommends that an organization using private addresses choose randomly from the reserved pool when allocating internal sub-blocks, to reduce the risk of a clash if two organizations later connect.[3] If every office picks 192.168.0.0/24 or 192.168.1.0/24, a future VPN between them collides on day one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks: common subnet mask mistakes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mistake&lt;/th&gt;
&lt;th&gt;What you see&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Wrong mask on one host | Host reaches some neighbors but not others | A host at 192.168.1.10 set to /24 on a /25 network treats 192.168.1.130 as local (the AND matches), while the real network puts that address behind the router. With the correct /25 mask the same test says "not local". I checked both results with a script. | Compare the mask on every host and on the router interface; they must all agree |&lt;/p&gt;

&lt;p&gt;| Non-contiguous mask | Hard-to-read subnets; a script refused to parse it | RFC 950 allowed masks with non-adjacent bits and gave 255.255.255.88 (01011000) as an example, but recommends the subnet bits be contiguous.[1] Python's &lt;code&gt;ipaddress&lt;/code&gt; module refused to parse that mask as a network. | Use contiguous masks only; stick to the table above |&lt;/p&gt;

&lt;p&gt;| Off-by-one on usable hosts | The plan promises 64 hosts per /26 and the 63rd device has no address | A /26 has 64 addresses but 62 usable hosts; the first is the network and the last is the broadcast | Use 2^(32-N) - 2, and size up when you plan for growth |&lt;/p&gt;

&lt;p&gt;| Assigning the network or broadcast address to a host | The address is reserved for the subnet itself, not for a device | For 192.168.10.64/26 those are .64 and .127 | Stay inside the first-to-last usable range |&lt;/p&gt;

&lt;p&gt;| Wrong base for a block | "192.168.10.100/26" entered as a network ID | A /26 network must start on a multiple of 64; .100 is inside the .64 block | Round down to the block start: 192.168.10.64/26 |&lt;/p&gt;

&lt;p&gt;| /31 on one end of a link | The link may not operate correctly | RFC 3021 notes that a point-to-point link with only one end supporting /31 may not operate correctly[4] | Match the prefix length on both ends |&lt;/p&gt;

&lt;p&gt;| Reading 172.16.0.0/12 as 172.16.x.x only | Overlap with 172.20.x.x or 172.31.x.x networks you thought were public | The /12 block covers 172.16.0.0 to 172.31.255.255[3] | Treat the whole 16-network span as private space |&lt;/p&gt;

&lt;p&gt;| Host bits set in a CIDR block | Tool reports "has host bits set" or silently rewrites it | 172.20.5.9/12 is not a network address; the network is 172.16.0.0/12, as Python confirmed | Zero the host bits before you write a route or ACL |&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;p&gt;A /N prefix keeps N bits for the network and leaves 32-N for hosts. Total addresses are 2^(32-N); usable hosts are that minus 2, except /31 (2, for point-to-point links under RFC 3021) and /32 (a single host route). The mask octet in the active byte is 256 minus the block size, and blocks start at multiples of their size. A host decides local versus gateway by ANDing the destination and its own address with its own mask and comparing. Private space is 10/8, 172.16/12 and 192.168/16. When you need numbers for a specific address, use a subnet calculator and check the result against the table above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc950.txt" rel="noopener noreferrer"&gt;RFC 950: Internet Standard Subnetting Procedure, J. Mogul and J. Postel, August 1985 (accessed November 26, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc4632.txt" rel="noopener noreferrer"&gt;RFC 4632: Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan, BCP 122, IETF, August 2006 (accessed November 26, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc1918.txt" rel="noopener noreferrer"&gt;RFC 1918: Address Allocation for Private Internets, BCP 5, IETF, February 1996 (accessed November 26, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  4. &lt;a href="https://www.rfc-editor.org/rfc/rfc3021.txt" rel="noopener noreferrer"&gt;RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links, IETF, December 2000 (accessed November 26, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/subnet-mask-cheat-sheet-cidr-table" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>subnetmask</category>
      <category>cidrtable</category>
      <category>cidrto</category>
      <category>24subnet</category>
    </item>
    <item>
      <title>An API Key Is a Secret That Identifies Your App</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Wed, 25 Nov 2026 01:23:51 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/an-api-key-is-a-secret-that-identifies-your-app-43c6</link>
      <guid>https://dev.to/akaranjkar08/an-api-key-is-a-secret-that-identifies-your-app-43c6</guid>
      <description>&lt;p&gt;&lt;strong&gt;An API key is a secret string that an app sends with every request so the server can tell which client is calling.&lt;/strong&gt; Anyone who holds the string can use it: RFC 6750 describes this property for bearer tokens, where any party in possession of the token can use it without proving anything else.[1] The short rule: treat it like a password for your app, send it in a request header, keep it out of source code and rotate it on a schedule. The rest of this guide covers what a key proves, where to put it in a request, how to store it, and what to do when one leaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an API key is, and what it is not
&lt;/h2&gt;

&lt;p&gt;Stripe calls its secret keys a form of account credentials, like a username and password.[5] That is the right mental model, with one twist. A password belongs to a person. An API key belongs to a program, a project or an account, and it travels with every call that program makes.&lt;/p&gt;

&lt;p&gt;OWASP gives two reasons a service issues keys. Public services without access control risk being farmed, which leads to excessive bills for bandwidth or compute. Keys also let organizations monetize an API, because clients get access in line with a purchased plan instead of being blocked at high call rates.[2] Neither reason is "prove this is a trustworthy person."&lt;/p&gt;

&lt;p&gt;The word "key" hides four separate jobs. Keep them apart and the error codes further down are easier to read.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;th&gt;Question the server asks&lt;/th&gt;
&lt;th&gt;What the key does&lt;/th&gt;
&lt;th&gt;Failure response&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Identification | Which client is this? | Ties the call to an account or a purchased access plan[2] | Key missing or unknown |&lt;/p&gt;

&lt;p&gt;| Authentication | Is the secret real and still valid? | Proves the caller holds a key the server issued | 401: wrong or no authentication[2] |&lt;/p&gt;

&lt;p&gt;| Authorization | Is this key allowed to do this? | Depends on the permissions attached to the key, such as Stripe's restricted keys[5] | 403: authenticated, but no permission[2] |&lt;/p&gt;

&lt;p&gt;| Rate limiting | Is this client calling too fast? | Lets the server reject callers that send requests too quickly | 429 Too Many Requests[2] |&lt;/p&gt;

&lt;p&gt;A key authenticates weakly. Possession is the only proof, so a leaked key works for whoever finds it. OWASP says API keys issued to third-party clients are relatively easy to compromise, and tells teams not to rely exclusively on them to protect sensitive, critical or high-value resources.[2] For anything that moves money or exposes customer data, add scoped permissions and short lifetimes on top.&lt;/p&gt;

&lt;h3&gt;
  
  
  API key vs OAuth access token
&lt;/h3&gt;

&lt;p&gt;An OAuth 2.0 access token is issued by an authorization server and represents a grant's scope, duration and other attributes.[1] RFC 6750 recommends short-lived bearer tokens of one hour or less, because that reduces the impact of a leak.[1] An API key is whatever your vendor's dashboard hands you. Lifetimes are vendor-specific: OpenAI, for one, recommends setting an expiration date when you create a project key.[6] A key with no expiry stays valid until you revoke it, so the leak window can be long, which is why rotation matters below.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to send an API key in a request
&lt;/h2&gt;

&lt;p&gt;RFC 6750 defines three ways to send a bearer token: the &lt;code&gt;Authorization&lt;/code&gt; header, a form-encoded body parameter and a URI query parameter. Clients must not use more than one in the same request.[1] The spec is clear about which one to pick: clients SHOULD use the &lt;code&gt;Authorization&lt;/code&gt; header with the &lt;code&gt;Bearer&lt;/code&gt; scheme, and resource servers MUST support it.[1] One scoping note: RFC 6750 covers OAuth bearer tokens and does not mention API keys by name. It applies here because a key sent in a header behaves like a bearer token, but your vendor's documentation has the final word. This is the RFC's own example, with the token swapped for a placeholder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="nc"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;
&lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bearer&lt;/span&gt; &lt;span class="no"&gt;YOUR_API_KEY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a shell, set the key as a variable for the current session and let the command read it. Stripe's docs use exactly this pattern for code examples, and note that the variable clears when you close the terminal.[5] OpenAI's production guide shows the same header shape, &lt;code&gt;Authorization: Bearer $OPENAI_API_KEY&lt;/code&gt;.[6] The host below is a placeholder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_API_KEY

curl https://api.example.com/v1/things \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $API_KEY"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same call from Node, reading the key from the environment and refusing to run without it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;API_KEY&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'API_KEY is not set'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://api.example.com/v1/things'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Bearer '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Request failed: '&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Header vs query string vs body
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Looks like&lt;/th&gt;
&lt;th&gt;RFC 6750 verdict&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Authorization header | &lt;code&gt;Authorization: Bearer YOUR_API_KEY&lt;/code&gt; | Clients SHOULD use it; servers MUST support it[1] | A header is not part of the URL; RFC 6750 warns that URLs can end up in browser history and server logs[1] |&lt;/p&gt;

&lt;p&gt;| Form-encoded body | &lt;code&gt;access_token=YOUR_API_KEY&lt;/code&gt; | SHOULD NOT be used except where browsers cannot reach the header; never with GET[1] | Strict conditions: single-part body, ASCII only, form content type |&lt;/p&gt;

&lt;p&gt;| Query string | &lt;code&gt;?access_token=YOUR_API_KEY&lt;/code&gt; | SHOULD NOT be used unless the header and body are both impossible[1] | The URL is likely to be logged[1] |&lt;/p&gt;

&lt;p&gt;The query string is the one to avoid. RFC 6750 says the method documents current use and is not recommended because of its security deficiencies.[1] OWASP's REST cheat sheet agrees and marks this shape as "NOT OK" because the key is in the URL:[2]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/controller/123/action?apiKey=YOUR_API_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OWASP's reasoning is that passwords, security tokens and API keys in a URL can be captured in web server logs, which makes those logs valuable to an attacker. Its rule: in &lt;code&gt;GET&lt;/code&gt; requests, send sensitive data in an HTTP header; in &lt;code&gt;POST&lt;/code&gt; and &lt;code&gt;PUT&lt;/code&gt; requests, use the body or a header.[2]&lt;/p&gt;

&lt;p&gt;One caveat. Bearer is the scheme RFC 6750 registers, but an API is free to require something else, such as a custom header. MDN lists several other schemes that ride in the same &lt;code&gt;Authorization&lt;/code&gt; header, including Basic, Digest and &lt;code&gt;AWS4-HMAC-SHA256&lt;/code&gt;.[7] The vendor's documentation decides the exact header name and format. If you use Basic, remember that base64 is reversible, so it offers no cryptographic security on its own.[7]&lt;/p&gt;

&lt;p&gt;Whatever the method, use HTTPS. OWASP says secure REST services must only provide HTTPS endpoints, which protects credentials such as API keys in transit.[2] RFC 6750 makes TLS mandatory for bearer token use.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  Where an API key is allowed to live
&lt;/h2&gt;

&lt;p&gt;Stripe's guidance states the rule clearly, and OpenAI's production guide says the same: avoid exposing keys in code or public repositories.[6] Under Stripe's rules, secret keys must stay in your server environment. Never put them in source code, because bad actors continuously scan public repositories, and even private repositories can be exposed through development environments.[5] Never embed them in applications either, since unauthorized parties can unpack an app to search for embedded keys. For client-side use, Stripe tells you to embed its publishable keys instead.[5]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Place&lt;/th&gt;
&lt;th&gt;Verdict&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Source code, committed to Git | Never | Public repositories are scanned continuously; private ones leak through developer environments[5] |&lt;/p&gt;

&lt;p&gt;| Browser or mobile app | Never for secret keys | Apps can be unpacked to find embedded keys[5] |&lt;/p&gt;

&lt;p&gt;| Environment variable on the server | Acceptable | Stripe names it as the fallback when no vault exists;[5] OpenAI lists environment variables or a secret management service[6] |&lt;/p&gt;

&lt;p&gt;| Secrets vault or manager | Preferred | Keeps the value out of source, CI config and developer environments, and adds an audit log of every access[5] |&lt;/p&gt;

&lt;p&gt;| Docker &lt;code&gt;ENV&lt;/code&gt; or &lt;code&gt;ARG&lt;/code&gt; | Never | They can easily leak with the container definitions[3] |&lt;/p&gt;

&lt;p&gt;| Email, chat, support tickets | Never | Share keys through secret-management tools; Stripe never asks for your secret key[5] |&lt;/p&gt;

&lt;p&gt;Environment variables have their own trap. Stripe warns against exposing them to users, for example by printing them on error pages or by leaving diagnostic modes open to a broad audience.[5] A vault, in Stripe's description, stores credentials separately from your code and supplies them at runtime; your code refers to the key by name, and you can revoke access instantly without redeploying.[5]&lt;/p&gt;

&lt;p&gt;Stripe also recommends a pre-commit hook that rejects commits containing keys a secret scanner detects. If you find a key in code, assume it is already exposed and compromised.[5]&lt;/p&gt;

&lt;h2&gt;
  
  
  Limit what a key can do
&lt;/h2&gt;

&lt;p&gt;A key that can do everything makes every leak a worst-case leak. The providers' docs point the same way on narrowing it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use restricted keys with specific privileges, not one broad secret key. Stripe's example is an invoicing system that can manage invoices and nothing else, or a read-only key for a third party that monitors disputes.[5]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restrict by network when your service sends requests from stable IP addresses. Stripe can block requests made with your keys from anywhere else.[5]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Give each environment its own project. OpenAI suggests separate staging and production projects, with user access to production limited and custom rate and spend limits per project.[6]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set spend alerts, and treat hard spend limits with care. OpenAI notes that a hard limit stops affected API traffic when tracked spend reaches it, so read the guide before enabling one in production.[6]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rotate keys before you have to
&lt;/h2&gt;

&lt;p&gt;OWASP's argument for rotation is simple: rotate regularly so that stolen credentials work only for a short time. It adds that the right lifetime depends on what the secret protects, anywhere from minutes to years.[3]&lt;/p&gt;

&lt;p&gt;Stripe adds that practicing rotation confirms you know where each key is used and that your team can replace one on short notice.[5]&lt;/p&gt;

&lt;p&gt;OpenAI documents the sequence that avoids downtime. Set an expiration date when you create a project key, and before it expires: create a replacement, update your applications to use it, then revoke the old key once you have verified the replacement works.[6] Revoke last, not first. Revoking first turns a routine rotation into an outage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do when an API key leaks
&lt;/h2&gt;

&lt;p&gt;Stripe draws a useful line. Exposure means the key became visible somewhere it should not have, such as a public repository, a log file or an email. Compromise means there is evidence of unauthorized use.[5] Its instruction covers both: if a key is exposed or compromised, rotate it immediately even if you are not sure anyone saw it.[5] The response, in order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a replacement key and revoke the leaked one.&lt;/strong&gt; GitHub's guidance on a secret scanning alert is to rotate the affected credential immediately.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the new key&lt;/strong&gt; through your vault or environment configuration, so every service that used the old key switches over. Revoking before the new key is live can cause downtime. For a leaked key that trade is usually worth it, but that is our judgment, not a vendor rule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Do not spend the first hour rewriting Git history.&lt;/strong&gt; GitHub says removing a secret from history is time-intensive and often unnecessary if you have already revoked the credential.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read the request logs&lt;/strong&gt; for the key's usage window to find calls you did not make. Stripe recommends auditing request logs to spot misused keys.[5]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Find the cause&lt;/strong&gt;: a committed file, a log line, a chat message, a client bundle. Fix that path, or the next key leaks the same way.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Detection helps but is not a plan. GitHub's secret scanning covers the entire Git history on all branches, plus issue and pull request text, discussions, wikis and secret gists. It runs automatically and free on public repositories, and organization-owned private repositories need GitHub Secret Protection.[4] For partner providers, GitHub notifies the provider so it can act, for example by revoking the credential.[4] Stripe sometimes deactivates a detected key proactively but does not guarantee detection of every exposed key.[5] For setup details on the newest layer of scanning, see WOWHOW's guide to &lt;a href="https://dev.to/blogs/copilot-secret-scanning-security-review-setup-cli-app-sdk-code-review"&gt;Copilot secret scanning&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Watch usage as well. OWASP says to check whether the caller comes from an expected IP with an expected user agent, and if not, to alert and assume the secret is compromised.[3]&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks: errors and fixes
&lt;/h2&gt;

&lt;p&gt;When a key-authenticated call fails, the status code usually says which of the three jobs went wrong. RFC 6750 maps its bearer error codes to statuses, and OWASP and MDN describe the 401 and 403 split.[1][2][8] For a deeper treatment of the two status codes, read WOWHOW's &lt;a href="https://dev.to/blogs/401-vs-403-http-status-codes-explained"&gt;401 vs 403 explainer&lt;/a&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Likely cause&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| 400, &lt;code&gt;invalid_request&lt;/code&gt; | The request is malformed, repeats a parameter or sends the token by more than one method[1] | Send the key in one place only, preferably the header |&lt;/p&gt;

&lt;p&gt;| 401, no key was sent | The server answers a request without credentials with &lt;code&gt;WWW-Authenticate: Bearer realm="example"&lt;/code&gt; and no error code[1] | Add the &lt;code&gt;Authorization&lt;/code&gt; header |&lt;/p&gt;

&lt;p&gt;| 401, &lt;code&gt;invalid_token&lt;/code&gt; | The token is expired, revoked, malformed or otherwise invalid[1] | Issue a new key and check it was copied whole |&lt;/p&gt;

&lt;p&gt;| 401 right after a leak | The provider may have deactivated the key after detecting exposure[5] | Rotate, then find the leak |&lt;/p&gt;

&lt;p&gt;| 403, &lt;code&gt;insufficient_scope&lt;/code&gt; | The credentials are valid but inadequate for this resource[1][8] | Create a key with the permission this call needs |&lt;/p&gt;

&lt;p&gt;| 404 where you expect a resource | Servers may return 404 to hide a resource from a caller without adequate privileges[8] | Check the key's permissions before the URL |&lt;/p&gt;

&lt;p&gt;| 429 | Too many requests for this key[2] | Back off, or move to a higher plan if the vendor offers one |&lt;/p&gt;

&lt;p&gt;The 401 response in the first non-error row looks like this in the RFC:[1]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt; &lt;span class="nc"&gt;Unauthorized&lt;/span&gt;
&lt;span class="na"&gt;WWW-Authenticate: Bearer realm&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"example"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;p&gt;An API key identifies a calling app and, by itself, authenticates it weakly, because whoever holds the string can use it. Send it in the &lt;code&gt;Authorization&lt;/code&gt; header over HTTPS, never in the URL. Keep it on the server, in a vault or an environment variable, and out of source code, client apps and container definitions. Narrow it with restricted permissions, separate projects and IP limits. Rotate on a schedule: create the new key, deploy it, then revoke the old one. When a key leaks, revoke and replace it first, read the logs second, and clean up Git history only if you still need to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc6750" rel="noopener noreferrer"&gt;RFC 6750: The OAuth 2.0 Authorization Framework: Bearer Token Usage, IETF, October 2012, updated by RFC 8996 and RFC 9700 (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html" rel="noopener noreferrer"&gt;REST Security Cheat Sheet, OWASP Cheat Sheet Series (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html" rel="noopener noreferrer"&gt;Secrets Management Cheat Sheet, OWASP Cheat Sheet Series (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.github.com/en/code-security/concepts/secret-security/secret-scanning" rel="noopener noreferrer"&gt;Secret scanning, GitHub Docs (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.stripe.com/keys-best-practices" rel="noopener noreferrer"&gt;Best practices for managing secret API keys, Stripe Documentation (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.openai.com/api/docs/guides/production-best-practices" rel="noopener noreferrer"&gt;Production best practices, OpenAI API documentation (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Authorization" rel="noopener noreferrer"&gt;Authorization header, MDN Web Docs (accessed November 25, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  8. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Authentication" rel="noopener noreferrer"&gt;HTTP authentication, MDN Web Docs (accessed November 25, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/what-is-an-api-key-explained" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>whatis</category>
      <category>apikey</category>
      <category>howto</category>
      <category>rotateapi</category>
    </item>
    <item>
      <title>401 vs 403: Unauthorized vs Forbidden Explained</title>
      <dc:creator>Anup Karanjkar</dc:creator>
      <pubDate>Tue, 24 Nov 2026 09:02:40 +0000</pubDate>
      <link>https://dev.to/akaranjkar08/401-vs-403-unauthorized-vs-forbidden-explained-32m9</link>
      <guid>https://dev.to/akaranjkar08/401-vs-403-unauthorized-vs-forbidden-explained-32m9</guid>
      <description>&lt;p&gt;&lt;strong&gt;HTTP 401 Unauthorized means the request lacks valid authentication credentials, while HTTP 403 Forbidden means the server understood the request and refuses to fulfill it.&lt;/strong&gt;[1][2] In short: 401 asks "who are you?" and 403 answers "permission denied." Despite the historical label "Unauthorized," RFC 9110 defines 401 around authentication, and requires every 401 response to carry a &lt;code&gt;WWW-Authenticate&lt;/code&gt; header explaining how to authenticate.[1][3] This guide covers the exact RFC 9110, RFC 6750, and RFC 9111 rules, when to return 404 instead of 403, production server and client code patterns, and the mistakes that break API auth flows. To look up any response code alongside its headers and retry behavior, open the &lt;a href="https://dev.to/tools/http-status-codes"&gt;HTTP status codes reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  401 vs 403 at a glance
&lt;/h2&gt;

&lt;p&gt;The fastest way to separate the two codes is to check whether the server could verify the caller's identity and whether retrying with refreshed credentials can fix the error.[1][2]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;401 Unauthorized&lt;/th&gt;
&lt;th&gt;403 Forbidden&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| Core meaning (RFC 9110) | Request lacks valid authentication credentials for the target resource[1] | Server understood the request but refuses to fulfill it[2] |&lt;/p&gt;

&lt;p&gt;| Security concept | Authentication (identity missing, expired, or invalid)[1][6] | Authorization or policy refusal (role, scope, IP, or state)[2][7] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;WWW-Authenticate&lt;/code&gt; header | &lt;strong&gt;MUST&lt;/strong&gt; be sent with at least one challenge[1][3] | Optional; server &lt;strong&gt;MAY&lt;/strong&gt; send it (e.g., OAuth 2.0 &lt;code&gt;insufficient_scope&lt;/code&gt;)[3][4] |&lt;/p&gt;

&lt;p&gt;| OAuth 2.0 Bearer error (RFC 6750) | &lt;code&gt;invalid_token&lt;/code&gt; (expired, revoked, or malformed token)[4] | &lt;code&gt;insufficient_scope&lt;/code&gt; (valid token lacking required scope)[4] |&lt;/p&gt;

&lt;p&gt;| Client retry behavior | Client &lt;strong&gt;MAY&lt;/strong&gt; retry with a new or replaced &lt;code&gt;Authorization&lt;/code&gt; header[1] | Client &lt;strong&gt;SHOULD NOT&lt;/strong&gt; automatically repeat with the same credentials[2] |&lt;/p&gt;

&lt;p&gt;| Heuristic caching (RFC 9110) | Not heuristically cacheable[5] | Not heuristically cacheable[5] |&lt;/p&gt;

&lt;p&gt;| Can hide resource existence? | No — signals the endpoint requires authentication | Server &lt;strong&gt;MAY&lt;/strong&gt; return 404 Not Found instead to hide existence[2] |&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 401 is called "Unauthorized" even though it means unauthenticated
&lt;/h2&gt;

&lt;p&gt;The name &lt;code&gt;401 Unauthorized&lt;/code&gt; causes more API design bugs than almost any other HTTP status code. In everyday security vocabulary, &lt;em&gt;authentication&lt;/em&gt; verifies who is making a request, while &lt;em&gt;authorization&lt;/em&gt; checks what that verified identity is allowed to do. HTTP kept the original 1990s reason phrase "Unauthorized" for backwards compatibility, even though RFC 9110 Section 15.5.2 defines 401 explicitly in terms of authentication: "the request has not been applied because it lacks valid authentication credentials for the target resource."[1]&lt;/p&gt;

&lt;p&gt;RFC 9110 Section 15.1 also notes that reason phrases are only recommendations and can be omitted or replaced without affecting the protocol (HTTP/2 and HTTP/3 do not even transmit reason phrases on the wire).[5] Treat the numeric code &lt;code&gt;401&lt;/code&gt; as "unauthenticated" and &lt;code&gt;403&lt;/code&gt; as "forbidden," as both MDN Web Docs and the OWASP REST Security Cheat Sheet do.[6][7][8]&lt;/p&gt;

&lt;h2&gt;
  
  
  What RFC 9110 requires for 401 Unauthorized
&lt;/h2&gt;

&lt;p&gt;Return &lt;code&gt;401&lt;/code&gt; when the caller has not proven a valid identity for the request:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No &lt;code&gt;Authorization&lt;/code&gt; header, session cookie, or API key was supplied on a protected route.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A JWT or OAuth access token has expired, failed signature verification, has the wrong audience or issuer, or was revoked.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A session cookie has expired or was invalidated server-side on logout.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HTTP Basic credentials have an unknown username or wrong password.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is one hard normative rule that many REST APIs overlook. Under RFC 9110 Section 15.5.2 and Section 11.6.1, a server generating a &lt;code&gt;401&lt;/code&gt; response &lt;strong&gt;MUST&lt;/strong&gt; send a &lt;code&gt;WWW-Authenticate&lt;/code&gt; header field containing at least one challenge applicable to the target resource.[1][3] Proxies forwarding that response &lt;strong&gt;MUST NOT&lt;/strong&gt; modify any &lt;code&gt;WWW-Authenticate&lt;/code&gt; header fields.[3]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt; &lt;span class="nc"&gt;Unauthorized&lt;/span&gt;
&lt;span class="na"&gt;WWW-Authenticate: Bearer realm&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"api"&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"authentication_required"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Provide a valid Bearer token."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the client already sent an expired or invalid Bearer token, RFC 6750 Section 3.1 specifies that the resource server &lt;strong&gt;SHOULD&lt;/strong&gt; respond with &lt;code&gt;401&lt;/code&gt; and include &lt;code&gt;error="invalid_token"&lt;/code&gt; in the challenge. When the request carried no credentials at all, RFC 6750 says the server &lt;strong&gt;SHOULD NOT&lt;/strong&gt; include an error code or error details in &lt;code&gt;WWW-Authenticate&lt;/code&gt; — send a bare &lt;code&gt;Bearer realm="..."&lt;/code&gt; challenge instead.[4]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt; &lt;span class="nc"&gt;Unauthorized&lt;/span&gt;
&lt;span class="na"&gt;WWW-Authenticate: Bearer realm&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"api"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"invalid_token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error_description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"The access token expired"&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"invalid_token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Access token expired. Refresh and retry."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what RFC 9110 Section 15.5.2 says about retry loops: the user agent &lt;strong&gt;MAY&lt;/strong&gt; repeat the request with a new or replaced &lt;code&gt;Authorization&lt;/code&gt; header, and if the server returns the same challenge after authentication was already attempted, the user agent &lt;strong&gt;SHOULD&lt;/strong&gt; show the diagnostic response rather than looping indefinitely.[1]&lt;/p&gt;

&lt;h2&gt;
  
  
  What RFC 9110 requires for 403 Forbidden
&lt;/h2&gt;

&lt;p&gt;Return &lt;code&gt;403&lt;/code&gt; when the server understood the request and is refusing to carry it out.[2] Two distinct categories fall under 403:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authenticated caller, insufficient privileges:&lt;/strong&gt; The token or session is valid, so the server knows who the caller is, but the caller lacks the role, tenant membership, plan entitlement, or OAuth scope needed for the action.[2][4][8]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Policy refusal unrelated to credentials:&lt;/strong&gt; RFC 9110 Section 15.5.4 explicitly notes that "a request might be forbidden for reasons unrelated to the credentials."[2] Common examples include IP allowlist blocks, geo-restrictions, WAF rules, disabled accounts, or write attempts on a read-only resource.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Because re-sending the exact same credentials will not change the server's policy decision, RFC 9110 Section 15.5.4 states that the client &lt;strong&gt;SHOULD NOT&lt;/strong&gt; automatically repeat the request with the same credentials (though it &lt;strong&gt;MAY&lt;/strong&gt; retry with new or different credentials, such as a token that carries a higher scope).[2]&lt;/p&gt;

&lt;p&gt;For OAuth 2.0 Bearer tokens, RFC 6750 Section 3.1 defines the exact &lt;code&gt;403&lt;/code&gt; pattern when a valid token lacks required scopes: return &lt;code&gt;403 Forbidden&lt;/code&gt; with &lt;code&gt;error="insufficient_scope"&lt;/code&gt; and optionally list the missing scopes in the &lt;code&gt;scope&lt;/code&gt; attribute.[4]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;403&lt;/span&gt; &lt;span class="nc"&gt;Forbidden&lt;/span&gt;
&lt;span class="na"&gt;WWW-Authenticate: Bearer realm&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"api"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"insufficient_scope"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"billing:write"&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"insufficient_scope"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"required_scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"billing:write"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When debugging whether an API returned 401 or 403 for a JWT, inspect the token's &lt;code&gt;exp&lt;/code&gt; timestamp versus its &lt;code&gt;scope&lt;/code&gt; or &lt;code&gt;role&lt;/code&gt; claims in the &lt;a href="https://dev.to/tools/jwt-decoder"&gt;JWT decoder&lt;/a&gt;. An expired &lt;code&gt;exp&lt;/code&gt; belongs in 401; a valid, unexpired token missing the required claim belongs in 403.&lt;/p&gt;

&lt;h2&gt;
  
  
  OAuth 2.0 Bearer error mapping: 400 vs 401 vs 403
&lt;/h2&gt;

&lt;p&gt;API teams often lump malformed auth headers together with expired tokens. RFC 6750 Section 3.1 separates three failure modes across three distinct status codes:[4]&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;RFC 6750 error code&lt;/th&gt;
&lt;th&gt;HTTP status&lt;/th&gt;
&lt;th&gt;When to use it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;| &lt;code&gt;invalid_request&lt;/code&gt; | &lt;code&gt;400 Bad Request&lt;/code&gt; | Missing required parameter, duplicate parameter, malformed syntax, or sending an access token in more than one place (for example, both a header and query string)[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;invalid_token&lt;/code&gt; | &lt;code&gt;401 Unauthorized&lt;/code&gt; | Token is expired, revoked, malformed, or otherwise fails verification; client may fetch a fresh token and retry[4] |&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;insufficient_scope&lt;/code&gt; | &lt;code&gt;403 Forbidden&lt;/code&gt; | Token is valid, but the endpoint requires higher privileges; server may advertise needed scopes via &lt;code&gt;scope="..."&lt;/code&gt;[4] |&lt;/p&gt;

&lt;h2&gt;
  
  
  When to return 404 instead of 403 (and the caching trap)
&lt;/h2&gt;

&lt;p&gt;Returning &lt;code&gt;403 Forbidden&lt;/code&gt; on an ID-addressed endpoint such as &lt;code&gt;GET /api/invoices/inv_98421&lt;/code&gt; confirms to the caller that invoice &lt;code&gt;inv_98421&lt;/code&gt; exists, even though the caller is not allowed to read it. If an attacker iterates through IDs, 403 versus 404 leaks which records exist in the database.&lt;/p&gt;

&lt;p&gt;RFC 9110 Section 15.5.4 explicitly authorizes hiding private resources behind 404: "An origin server that wishes to 'hide' the current existence of a forbidden target resource MAY instead respond with a status code of 404 (Not Found)."[2] Section 15.5.5 mirrors that rule in the definition of 404: the server either did not find a representation "or is not willing to disclose that one exists."[5]&lt;/p&gt;

&lt;p&gt;Use this split in practice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Return 404 instead of 403&lt;/strong&gt; for private, user-scoped, or tenant-scoped records where confirming existence is a data leak (invoices, private repositories, direct messages, another organization's documents).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Return 403&lt;/strong&gt; for known capability or role checks where the endpoint's existence is public (for example, a logged-in member calling &lt;code&gt;POST /api/org/billing/plan&lt;/code&gt; without the admin role, or a valid OAuth token missing &lt;code&gt;reports:write&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Watch the caching difference when swapping 403 for 404.&lt;/strong&gt; Under RFC 9110 Section 15.1, neither &lt;code&gt;401&lt;/code&gt; nor &lt;code&gt;403&lt;/code&gt; is heuristically cacheable, whereas &lt;code&gt;404&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; heuristically cacheable by default unless explicit cache controls prevent it.[5] Under RFC 9111 Section 3.5, a shared cache must not reuse a cached response to a request containing an &lt;code&gt;Authorization&lt;/code&gt; header unless the response includes &lt;code&gt;must-revalidate&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt;, or &lt;code&gt;s-maxage&lt;/code&gt;.[9] Cookie-authenticated endpoints do not carry an &lt;code&gt;Authorization&lt;/code&gt; header, so always send &lt;code&gt;Cache-Control: private, no-store&lt;/code&gt; on authenticated endpoints that mask 403 as 404 — otherwise a misconfigured CDN could cache one user's 404 and serve it to the record's actual owner.&lt;/p&gt;

&lt;h2&gt;
  
  
  401 vs 403 vs 407: where proxies fit
&lt;/h2&gt;

&lt;p&gt;Corporate networks and egress proxies introduce a third authentication code: &lt;code&gt;407 Proxy Authentication Required&lt;/code&gt;. RFC 9110 Section 15.5.8 defines 407 as parallel to 401, except the challenge comes from an HTTP proxy rather than the origin server.[5] The proxy &lt;strong&gt;MUST&lt;/strong&gt; send a &lt;code&gt;Proxy-Authenticate&lt;/code&gt; header, and the client answers with &lt;code&gt;Proxy-Authorization&lt;/code&gt;. Application servers should never return 407 for app-level login failures; reserve 401 for origin authentication and 403 for origin authorization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production server pattern: separating authN and authZ
&lt;/h2&gt;

&lt;p&gt;Clean server code evaluates authentication first and authorization second so a missing token never falls through to a 403 and a missing role never triggers a token-refresh loop. Here is a minimal Next.js Route Handler pattern (for full route middleware architecture, see the &lt;a href="https://dev.to/blogs/nextjs-16-api-routes-middleware-complete-tutorial-2026"&gt;Next.js 16 API routes and middleware guide&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;NextRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'next/server'&lt;/span&gt;

&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;VerifiedUser&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="n"&gt;orgId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;verifyBearerToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bearer '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'missing'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bearer '&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'missing'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Replace with signature, exp, iss, and aud verification&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;lookupAndVerifyJwt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'invalid'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;DELETE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;NextRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;verifyBearerToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'authorization'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// 1. Authentication check -&amp;gt; 401 + mandatory WWW-Authenticate&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;challenge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'missing'&lt;/span&gt;
        &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'Bearer realm="api"'&lt;/span&gt;
        &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Bearer realm="api", error="invalid_token"'&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'missing'&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'authentication_required'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'invalid_token'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'WWW-Authenticate'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;challenge&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'no-store'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// 2. Scope / role check -&amp;gt; 403 with required scope&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'projects:delete'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'insufficient_scope'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required_scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'projects:delete'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="s1"&gt;'WWW-Authenticate'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="s1"&gt;'Bearer realm="api", error="insufficient_scope", scope="projects:delete"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'no-store'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// 3. Tenant ownership check -&amp;gt; 404 to avoid leaking foreign IDs&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;findProjectForOrg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orgId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'not_found'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'private, no-store'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;deleteProject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NextResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;204&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every branch maps directly to the RFC rules above: missing tokens get a bare &lt;code&gt;401&lt;/code&gt; challenge, bad or expired tokens get &lt;code&gt;401&lt;/code&gt; with &lt;code&gt;error="invalid_token"&lt;/code&gt;, missing scopes get &lt;code&gt;403&lt;/code&gt; with &lt;code&gt;error="insufficient_scope"&lt;/code&gt;, and cross-tenant ID lookups return a non-cached &lt;code&gt;404&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Client-side handling: refresh on 401 once, never auto-retry 403
&lt;/h2&gt;

&lt;p&gt;The biggest operational reason to keep 401 and 403 distinct is client interceptor behavior. Most HTTP clients and frontend SDKs attach an interceptor that watches for &lt;code&gt;401&lt;/code&gt;, exchanges a refresh token for a new access token, and replays the failed request once. If your backend accidentally sends &lt;code&gt;401&lt;/code&gt; when a user lacks an admin role, that interceptor refreshes a valid token, replays the request, gets another &lt;code&gt;401&lt;/code&gt;, and either loops or logs the user out.&lt;/p&gt;

&lt;p&gt;Follow three client rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;On 401:&lt;/strong&gt; Attempt a single credential refresh (if the request has not already been retried), replay once with the new &lt;code&gt;Authorization&lt;/code&gt; header, and redirect to sign-in or surface an auth error if the second attempt still returns 401.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;On 403:&lt;/strong&gt; Do &lt;em&gt;not&lt;/em&gt; automatically retry with the same credentials, and do &lt;em&gt;not&lt;/em&gt; wipe the user's session.[2] Show a clear permission message or prompt for step-up consent if the response advertises a required OAuth &lt;code&gt;scope&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backoff applies to transient errors, not 403:&lt;/strong&gt; Exponential backoff is for transient faults such as &lt;code&gt;429&lt;/code&gt; or &lt;code&gt;503&lt;/code&gt; — model those retry schedules with the &lt;a href="https://dev.to/tools/exponential-backoff-calculator"&gt;exponential backoff calculator&lt;/a&gt;, and exclude &lt;code&gt;403&lt;/code&gt; from automatic retries.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Five common 401 and 403 mistakes to avoid
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Returning 401 without &lt;code&gt;WWW-Authenticate&lt;/code&gt;:&lt;/strong&gt; Violates RFC 9110 Section 15.5.2's MUST requirement and breaks strict HTTP/OAuth clients that inspect the challenge to decide how to re-authenticate.[1]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Returning 401 for missing roles or permissions:&lt;/strong&gt; Causes SPA and mobile interceptors to treat a valid session as logged out and trigger unnecessary token refreshes or forced sign-outs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Returning 403 for expired tokens:&lt;/strong&gt; Prevents the client from triggering silent token refresh, leaving users stuck on a "permission denied" screen until they manually reload and sign in again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Returning 403 on cross-tenant object IDs:&lt;/strong&gt; Lets callers enumerate valid IDs belonging to other customers instead of returning &lt;code&gt;404&lt;/code&gt; with &lt;code&gt;Cache-Control: private, no-store&lt;/code&gt;.[2]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Returning 200 OK with an error JSON body:&lt;/strong&gt; Breaks standard HTTP tooling, telemetry, alerting, and caches — OWASP explicitly advises returning the semantically appropriate status code rather than wrapping auth errors in 200 or 404.[8]&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Quick decision checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No credentials provided on a protected endpoint? Return &lt;strong&gt;401&lt;/strong&gt; with &lt;code&gt;WWW-Authenticate: Bearer realm="..."&lt;/code&gt; (no &lt;code&gt;error&lt;/code&gt; parameter).[1][4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Credentials expired, revoked, or invalid signature? Return &lt;strong&gt;401&lt;/strong&gt; with &lt;code&gt;WWW-Authenticate: Bearer realm="...", error="invalid_token"&lt;/code&gt;.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Malformed auth header or duplicate token transport? Return &lt;strong&gt;400&lt;/strong&gt; with &lt;code&gt;invalid_request&lt;/code&gt;.[4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Valid credentials, but wrong role, plan, or OAuth scope? Return &lt;strong&gt;403&lt;/strong&gt; (optionally with &lt;code&gt;error="insufficient_scope"&lt;/code&gt; and &lt;code&gt;scope="..."&lt;/code&gt;).[2][4]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Blocked by IP allowlist, WAF, or account suspension? Return &lt;strong&gt;403&lt;/strong&gt;.[2]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authenticated user requesting another tenant's private ID? Return &lt;strong&gt;404&lt;/strong&gt; with &lt;code&gt;Cache-Control: private, no-store&lt;/code&gt;.[2][5]&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Proxy requires credentials before forwarding? Return &lt;strong&gt;407&lt;/strong&gt; with &lt;code&gt;Proxy-Authenticate&lt;/code&gt;.[5]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.2" rel="noopener noreferrer"&gt;RFC 9110: HTTP Semantics, Section 15.5.2 — 401 Unauthorized, IETF, June 2022 (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.4" rel="noopener noreferrer"&gt;RFC 9110: HTTP Semantics, Section 15.5.4 — 403 Forbidden, IETF, June 2022 (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-11.6.1" rel="noopener noreferrer"&gt;RFC 9110: HTTP Semantics, Section 11.6.1 — WWW-Authenticate, IETF, June 2022 (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc6750.html#section-3.1" rel="noopener noreferrer"&gt;RFC 6750: The OAuth 2.0 Authorization Framework: Bearer Token Usage, Section 3.1 — Error Codes, IETF, October 2012 (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9110.html#section-15.1" rel="noopener noreferrer"&gt;RFC 9110: HTTP Semantics, Sections 15.1, 15.5.5, and 15.5.8 — Status Code Overview, 404 Not Found, and 407 Proxy Authentication Required, IETF, June 2022 (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401" rel="noopener noreferrer"&gt;401 Unauthorized — HTTP Status Codes, MDN Web Docs (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403" rel="noopener noreferrer"&gt;403 Forbidden — HTTP Status Codes, MDN Web Docs (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html" rel="noopener noreferrer"&gt;REST Security Cheat Sheet — HTTP Return Codes, OWASP Cheat Sheet Series (accessed November 24, 2026)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  9. &lt;a href="https://www.rfc-editor.org/rfc/rfc9111.html#section-3.5" rel="noopener noreferrer"&gt;RFC 9111: HTTP Caching, Section 3.5 — Storing Responses to Authenticated Requests, IETF, June 2022 (accessed November 24, 2026)&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://wowhow.cloud/blogs/401-vs-403-http-status-codes-explained" rel="noopener noreferrer"&gt;wowhow.cloud&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>401vs</category>
      <category>http401</category>
      <category>401unauthorized</category>
      <category>whento</category>
    </item>
  </channel>
</rss>
