<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~files/atom-premium.xsl"?>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedpress="https://feed.press/xmlns" xmlns:media="http://search.yahoo.com/mrss/" xmlns:podcast="https://podcastindex.org/namespace/1.0">
  <feedpress:locale>en</feedpress:locale>
  <feedpress:newsletterId>telerik-blogs-web</feedpress:newsletterId>
  <link rel="hub" href="https://feedpress.superfeedr.com/"/>
  <logo>https://static.feedpress.com/logo/telerik-blogs--web-5ab52bef0a72f.jpg</logo>
  <title type="text">Telerik Blogs | Web</title>
  <subtitle type="text">The official blog of Progress Telerik - expert articles and tutorials for developers.</subtitle>
  <id>uuid:4764263f-7346-492b-a15b-64eb3b84fc95;id=2763</id>
  <updated>2026-11-30T00:42:24Z</updated>
  <link rel="alternate" href="https://www.telerik.com/"/>
  <link rel="self" type="application/atom+xml" href="https://feeds.telerik.com/blogs/web"/>
  <entry>
    <id>urn:uuid:c9024558-9f1c-4719-b110-5874ef6c4d7f</id>
    <title type="text">Quiet Quality-of-Life Wins in Vue 3.5</title>
    <summary type="text">Vue 3.5 was a minor release, but it came with some nice quality-of-life upgrades worth exploring. Here’s what one Vue developer uses daily.</summary>
    <published>2026-11-25T17:19:51Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Marina Mosti </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17540843/quiet-quality-life-wins-vue-3-5"/>
    <content type="text"><![CDATA[<p><span class="featured">Vue 3.5 was a minor release, but it came with some nice quality-of-life upgrades worth exploring. Here&rsquo;s what one Vue developer uses daily.</span></p><p>Back in 2019, I wrote <a target="_blank" href="https://www.telerik.com/blogs/how-to-target-the-dom-in-vue">How to Target the DOM in Vue</a>, which was all about <code>ref</code> and the edge cases that come with grabbing a real element out of your template. That article is old enough to have jQuery comparisons in it (). The interesting part is that the advice barely changed for five years, and then Vue 3.5 quietly changed a piece of it.</p><p>Big Vue releases get a blog post, a conference talk and a week of discussion. Minor releases get a changelog that most of us skim on the way to fixing something else. Vue 3.5 shipped in September 2024 and it is full of small things that remove a line or two of boilerplate from files you touch every week.</p><p>We&rsquo;ll go through <code>useTemplateRef</code>, <code>useId</code>, reactive props destructure, <code>onWatcherCleanup</code>, deferred <code>Teleport</code> and lazy hydration, and for each one I want to show you the annoying thing it replaces.</p><h2 id="template-refs-by-name-with-usetemplateref">Template Refs by Name with useTemplateRef</h2><p>Let&rsquo;s start with template refs, since that&rsquo;s where we came in. Here is the shape you have written a hundred times.</p><p><code>MessageBox.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { ref, onMounted } from 'vue'

const composer = ref(null)

onMounted(() =&gt; {
  composer.value.focus()
})
&lt;/script&gt;

&lt;template&gt;
  &lt;textarea ref="composer" rows="4"&gt;&lt;/textarea&gt;
&lt;/template&gt;
</code></pre><p>This works because of a compiler trick. Vue looks at the <code>ref="composer"</code> attribute, finds a top-level variable in your <code>&lt;script setup&gt;</code> block called <code>composer</code>, and wires the two together for you. The name match is the whole mechanism.</p><p>That match is also the limitation. The <code>ref</code> attribute has to be a static string, and your variable has to be named exactly the same thing.</p><p>Vue 3.5 adds <code>useTemplateRef</code>, which takes the name as a regular function argument instead.</p><p><code>MessageBox.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { useTemplateRef, onMounted } from 'vue'

const el = useTemplateRef('composer')

onMounted(() =&gt; {
  el.value.focus()
})
&lt;/script&gt;

&lt;template&gt;
  &lt;textarea ref="composer" rows="4"&gt;&lt;/textarea&gt;
&lt;/template&gt;
</code></pre><p>Let&rsquo;s break it down. <code>useTemplateRef('composer')</code> gives you back a shallow ref, and Vue points it at whichever element is tagged <code>ref="composer"</code>. The value is <code>null</code> until the component mounts, and it goes back to <code>null</code> when the element is unmounted or hidden by a <code>v-if</code>.</p><p>Notice that the variable is now called <code>el</code> and nothing broke. The string is what binds, so you can name the variable whatever reads best.</p><p>One detail worth knowing. The ref you get back is typed <code>readonly</code>, and Vue warns you if you assign to it in development. That&rsquo;s a feature! Vue owns that value, and in the old pattern nothing stopped you from accidentally clobbering it. More safe, more better, I guess.</p><p>The part we actually care about is that the name can now come from outside the component, like an argument to a composable.</p><p><code>useCursorAtEnd.js</code></p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">import</span> <span class="token punctuation">{</span> useTemplateRef<span class="token punctuation">,</span> onMounted <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> SELECTABLE <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'text'</span><span class="token punctuation">,</span> <span class="token string">'search'</span><span class="token punctuation">,</span> <span class="token string">'url'</span><span class="token punctuation">,</span> <span class="token string">'tel'</span><span class="token punctuation">,</span> <span class="token string">'password'</span><span class="token punctuation">]</span>

<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">useCursorAtEnd</span><span class="token punctuation">(</span>fieldName<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> field <span class="token operator">=</span> <span class="token function">useTemplateRef</span><span class="token punctuation">(</span>fieldName<span class="token punctuation">)</span>

  <span class="token function">onMounted</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> el <span class="token operator">=</span> field<span class="token punctuation">.</span>value
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>el<span class="token punctuation">)</span> <span class="token keyword">return</span>

    el<span class="token punctuation">.</span><span class="token function">focus</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">if</span> <span class="token punctuation">(</span>el<span class="token punctuation">.</span>tagName <span class="token operator">!==</span> <span class="token string">'TEXTAREA'</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>SELECTABLE<span class="token punctuation">.</span><span class="token function">includes</span><span class="token punctuation">(</span>el<span class="token punctuation">.</span>type<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">return</span>

    el<span class="token punctuation">.</span><span class="token function">setSelectionRange</span><span class="token punctuation">(</span>el<span class="token punctuation">.</span>value<span class="token punctuation">.</span>length<span class="token punctuation">,</span> el<span class="token punctuation">.</span>value<span class="token punctuation">.</span>length<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>

  <span class="token keyword">return</span> field
<span class="token punctuation">}</span>
</code></pre><p>That one focuses a field and drops the cursor after the existing text, which is what you want for a rename box or an inline edit.</p><p>Focusing a field doesn&rsquo;t promise you anything about where the cursor lands. Browsers differ, so the user can end up at the start of the text or with the whole value selected, and either way they have to fix it before typing. Setting the range yourself is the only way to be sure.</p><p>Big disclaimer though. <code>setSelectionRange</code> only works on fields that support text selection, which means a <code>textarea</code> or an <code>input</code> of type <code>text</code>, <code>search</code>, <code>url</code>, <code>tel</code> or <code>password</code>. Point it at an <code>input type="email"</code> or an <code>input type="number"</code>, and the browser throws an <code>InvalidStateError</code> instead. That&rsquo;s what the <code>SELECTABLE</code> check is doing, because this composable takes the field name from the caller and can land on anything.</p><p>Now any component can call <code>useCursorAtEnd('composer')</code> and the composable finds the element on its own. It never has to care what that element is called, and you don&rsquo;t have to declare a ref in the component just to hand it over.</p><p>The <code>ref</code> attribute can also be a dynamic binding, so the name can be computed at runtime instead of hardcoded in the template. For a name that genuinely keeps changing, a function ref is still the tool, and it&rsquo;s clunkier to write.</p><p>One rule though: call <code>useCursorAtEnd</code> (or whatever your composable is called) at the top of your setup block. It reads the active component instance when it runs, so calling it from inside <code>onMounted</code> is already too late. Vue has placed the element by then, and a ref you set up at that point stays <code>null</code> until the next update.</p><p>To be quite honest with you, I don&rsquo;t think the plain <code>ref(null)</code> version is going away, and I don&rsquo;t plan to rewrite existing components. For a one-off focus call in a single file, it&rsquo;s fine and it&rsquo;s shorter. I reach for <code>useTemplateRef</code> when the name needs to travel, which in practice means composables.</p><h2 id="unique-ids-without-hand-rolling-them">Unique IDs Without Hand-Rolling Them</h2><p>Here&rsquo;s a problem that has annoyed me for years. You build a reusable form field, and you need to connect the <code>&lt;label&gt;</code> to the <code>&lt;input&gt;</code> with a matching <code>for</code> and <code>id</code> pair. That pair has to be unique on the page, and a reusable component has no idea how many copies of itself exist.</p><p>So we usually have to improvise, I&rsquo;m sure you&rsquo;ve shipped at least one of these.</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token comment">// a module-level counter</span>
<span class="token keyword">let</span> fieldCount <span class="token operator">=</span> <span class="token number">0</span>
<span class="token keyword">const</span> idFromCounter <span class="token operator">=</span> <span class="token template-string"><span class="token string">`field-</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>fieldCount<span class="token operator">++</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span>

<span class="token comment">// or a random string</span>
<span class="token keyword">const</span> idFromRandom <span class="token operator">=</span> <span class="token template-string"><span class="token string">`field-</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token number">36</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span>

<span class="token comment">// or make it the caller's problem, with a required prop</span>
<span class="token function">defineProps</span><span class="token punctuation">(</span><span class="token punctuation">{</span> id<span class="token punctuation">:</span> <span class="token punctuation">{</span> type<span class="token punctuation">:</span> String<span class="token punctuation">,</span> required<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><p>The counter works until you server-render. The server and the browser each start counting from zero at their own moment, so the two IDs don&rsquo;t match and you get a hydration mismatch.</p><p>The random string is worse, since it produces a different value on every single render. The required prop works fine, but it pushes a boring detail onto everyone who uses your component.</p><p>Vue 3.5 gives us <code>useId</code>.</p><p><code>FormField.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { useId } from 'vue'

defineProps({
  label: { type: String, required: true },
})

const model = defineModel({ type: String })
const id = useId()
&lt;/script&gt;

&lt;template&gt;
  &lt;div class="field"&gt;
    &lt;label :for="id"&gt;{{ label }}&lt;/label&gt;
    &lt;input :id="id" v-model="model" /&gt;
  &lt;/div&gt;
&lt;/template&gt;
</code></pre><p><code>useId()</code> hands you a fresh string every time you call it, and no two calls anywhere in the app produce the same one. That is true whether you call it twice in one component or render 20 copies of the same field. The reason it&rsquo;s worth switching is that the server and the browser agree on the value, so nothing mismatches during hydration.</p><p>Two caveats before you go sprinkling it everywhere.</p><p>First, don&rsquo;t call <code>useId()</code> inside a <code>computed()</code>. A computed only runs when something reads it, and <code>useId()</code> reads whichever component is active at that moment, which may not be yours. The server and the browser won&rsquo;t reach that first read at the same point either, so you&rsquo;re back to a hydration mismatch. Call <code>useId()</code> once in your setup block and read that variable from the computed.</p><p>Second, if you mount more than one Vue app on the same page, the generated IDs can collide across apps. There&rsquo;s a config for that, and you set it per app.</p><p><code>main.js</code></p><pre class=" language-javascript"><code class="prism  language-javascript">app<span class="token punctuation">.</span>config<span class="token punctuation">.</span>idPrefix <span class="token operator">=</span> <span class="token string">'checkout'</span>
</code></pre><p>Every ID from that app now starts with <code>checkout-</code>, so it can&rsquo;t clash with IDs from the app next to it.</p><h2 id="reactive-props-destructure-became-the-default">Reactive Props Destructure Became the Default</h2><p>This one changes the meaning of code you may already have written, so it&rsquo;s the one to read carefully.</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> <span class="token punctuation">{</span> total <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">,</span> label <span class="token operator">=</span> <span class="token string">'Items'</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">defineProps</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">'total'</span><span class="token punctuation">,</span> <span class="token string">'label'</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre><p>In Vue 3.4 and earlier, destructuring props like that quietly broke reactivity. You got the value at setup time, frozen forever, and updating the prop from the parent did nothing. It was a well-known footgun.</p><p>In 3.5 the compiler rewrites every access to a destructured prop back into <code>props.total</code> for you, so it&rsquo;s reactive and updates normally.</p><p>The nice side effect is that prop defaults are now just JavaScript default values, which is a lot more pleasant than a <code>default</code> key in an options object. It&rsquo;s especially nice with type-based declarations, where you used to need <code>withDefaults</code>.</p><p>Big disclaimer though. Reactivity survives inside your template and inside computed properties, but the moment you pass a destructured prop as an argument to a function, you&rsquo;re handing over a plain value and the tracking stops.</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> <span class="token punctuation">{</span> userId <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">defineProps</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">'userId'</span><span class="token punctuation">]</span><span class="token punctuation">)</span>

<span class="token function">watch</span><span class="token punctuation">(</span>userId<span class="token punctuation">,</span> fetchUser<span class="token punctuation">)</span> <span class="token comment">// compile error, userId is a plain string here</span>

<span class="token function">watch</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> userId<span class="token punctuation">,</span> fetchUser<span class="token punctuation">)</span> <span class="token comment">// correct</span>
</code></pre><p>Same rule for your own composables. Hand over <code>() =&gt; userId</code> instead of <code>userId</code>. Inside the composable, <code>toValue()</code> will unwrap it for you and keep the dependency tracked. If you already write composables that accept getters, nothing changes for you.</p><p>This last bit may be something worth linting for in big codebases.</p><h2 id="onwatchercleanup-for-cancelling-work-in-flight">onWatcherCleanup for Cancelling Work in Flight</h2><p>Watchers that kick off async work have always needed a way to cancel the previous run. The old approach was the third argument of the watcher callback, usually called <code>onCleanup</code>. Vue 3.5 adds <code>onWatcherCleanup</code> as an import, so the cleanup registration is a normal function call instead of a parameter you have to remember to accept.</p><p><code>SearchResults.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { ref, watch, onWatcherCleanup } from 'vue'

const query = ref('')
const results = ref([])

watch(query, async (newQuery) =&gt; {
  const controller = new AbortController()
  onWatcherCleanup(() =&gt; controller.abort())

  try {
    const response = await fetch(
      `https://myapp.com/search?q=${encodeURIComponent(newQuery)}`,
      { signal: controller.signal }
    )

    if (!response.ok) throw new Error('Search request failed')

    results.value = await response.json()
  } catch (error) {
    if (error.name !== 'AbortError') throw error
  }
})
&lt;/script&gt;

&lt;template&gt;
  &lt;input v-model="query" type="search" /&gt;
&lt;/template&gt;
</code></pre><p>This abort-the-previous-request shape is the one the Vue docs use in their <a target="_blank" href="https://vuejs.org/guide/essentials/watchers.html#side-effect-cleanup">side effect cleanup</a> section, and their version is worth a read too.</p><p>Let&rsquo;s break it down. Every time <code>query</code> changes, we build a fresh <code>AbortController</code> and register its <code>abort</code> as the cleanup for this run.</p><p>If the user types another character before the request comes back, Vue runs the cleanup first, the in-flight request is aborted, and only then does the new callback start. No more race where an older response lands after a newer one and overwrites your results.</p><p>Notice where the <code>onWatcherCleanup</code> call sits. It has to run during the synchronous part of the callback, which means before the first <code>await</code>. Put it after the fetch, and it will not register, because by then Vue has moved on and no longer knows which watcher you mean.</p><p>Vue does warn you in development rather than failing quietly, so check your console if a stale request sneaks through. If you genuinely need to register cleanup after an <code>await</code>, keep using the <code>onCleanup</code> parameter, which doesn&rsquo;t have that restriction.</p><p>The <code>catch</code> block is there because aborting a fetch makes it reject with an <code>AbortError</code>. That rejection is expected, so we swallow that one and rethrow everything else.</p><h2 id="deferred-teleport">Deferred Teleport</h2><p><code>&lt;Teleport&gt;</code> has always had one rule that surprises people. It looks for its destination the moment it mounts, and if that element isn&rsquo;t on the page yet, it gives up. So this fails.</p><p><code>AppLayout.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;template&gt;
  &lt;Teleport to="#drawer-slot"&gt;
    &lt;p&gt;I never arrive&lt;/p&gt;
  &lt;/Teleport&gt;

  &lt;div id="drawer-slot"&gt;&lt;/div&gt;
&lt;/template&gt;
</code></pre><p>The <code>&lt;div&gt;</code> is right there in the same template. But Teleport looks for its target during the same mounting pass, and at that point the <code>&lt;div&gt;</code> doesn&rsquo;t exist yet. The usual workarounds were moving the target into <code>index.html</code> or wrapping things in <code>v-if</code> plus <code>nextTick</code>.</p><p>Vue 3.5 adds a <code>defer</code> prop that waits until the current render cycle finishes before looking for the target.</p><p><code>AppLayout.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;template&gt;
  &lt;Teleport defer to="#drawer-slot"&gt;
    &lt;p&gt;I arrive on time&lt;/p&gt;
  &lt;/Teleport&gt;

  &lt;div id="drawer-slot"&gt;&lt;/div&gt;
&lt;/template&gt;
</code></pre><p>That&rsquo;s the whole fix, and it kills the ugliest workaround on this list.</p><p>One limit to know about. The wait is short. <code>defer</code> holds off until the current render pass is done, and that&rsquo;s it, so the target still has to exist by the time that pass ends. A container that only appears once a fetch resolves is already too late, and you get the same missing-target error you started with.</p><p>The place I actually use <code>defer</code> is layout components that own their own portal containers, since forcing those containers into the root HTML file feels wrong.</p><h2 id="lazy-hydration-if-you-server-render">Lazy Hydration, If You Server-Render</h2><p>Last one, and it only matters if you&rsquo;re doing SSR. Normally every component in a server-rendered page gets hydrated as soon as the JavaScript loads, whether the user can see it or not. A comments section three screens down costs you the same startup work as the thing at the top of the page.</p><p>Vue 3.5 lets an async component decide when it hydrates.</p><p><code>CommentsPanel.js</code></p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">import</span> <span class="token punctuation">{</span> defineAsyncComponent<span class="token punctuation">,</span> hydrateOnVisible <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> CommentsSection <span class="token operator">=</span> <span class="token function">defineAsyncComponent</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  loader<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./CommentsSection.vue'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  hydrate<span class="token punctuation">:</span> <span class="token function">hydrateOnVisible</span><span class="token punctuation">(</span><span class="token punctuation">{</span> rootMargin<span class="token punctuation">:</span> <span class="token string">'200px'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><p>Now the markup ships and renders, but the component isn&rsquo;t hydrated until it scrolls near the viewport, so nothing inside it is interactive yet. There are four built-in strategies.</p><ul><li><strong><code>hydrateOnVisible(options)</code></strong>: hydrates when the element comes into view, using <code>IntersectionObserver</code>. The options go straight to the observer, so <code>rootMargin</code> lets you start early. This is my default for anything below the fold.</li><li><strong><code>hydrateOnIdle(timeout)</code></strong>: hydrates inside a <code>requestIdleCallback</code>, and you can cap how long it&rsquo;s willing to wait (it defaults to 10 seconds). Good for widgets that sit off to the side but still get clicked.</li></ul><p>The other two are <code>hydrateOnInteraction(events)</code>, which waits for an event and then replays it so the first click isn&rsquo;t lost, and <code>hydrateOnMediaQuery(query)</code>, which stays asleep until the media query you give it starts matching.</p><p>Notice that <code>hydrateOnVisible</code> is its own import. That&rsquo;s on purpose, so your bundle only ships the strategies you actually use.</p><h2 id="wrapping-up">Wrapping Up</h2><p>None of this is going to change how you build Vue apps. That&rsquo;s the point of a minor release. What it does is remove six small annoyances, and three of them (<code>useId</code>, reactive props destructure and <code>onWatcherCleanup</code>) show up in the kind of code I write almost every day.</p><p>If you&rsquo;re on 3.4 and you skipped the upgrade, the reactive props destructure change is the one to look at first, since it turns a footgun into working code.</p><p>If you&rsquo;re already on 3.5 or later without knowing what came with it, go rewrite one form field with <code>useId</code> and enjoy deleting the counter.</p><p>Happy upgrading!</p><hr /><blockquote><p>Have you explored the Progress Kendo UI for <a target="_blank" href="https://www.telerik.com/kendo-vue-ui">Vue component library</a> yet? It comes with a free 30-day trial, so go for it!</p><br /><p><a href="https://www.telerik.com/try/kendo-vue-ui" target="_blank" class="Btn">Try Now</a></p></blockquote><img src="https://feeds.telerik.com/link/10827/17540843.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:057c1346-1924-44cd-82f2-0872d9f7fc77</id>
    <title type="text">Enhancing Blazor User Experience with Prebuilt Editors</title>
    <summary type="text">These editor-like components can help you improve the user experience of your Blazor application, with settings and customizations that adapt to the scenario you need.</summary>
    <published>2026-11-24T21:26:35Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Héctor Pérez </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17539504/enhancing-blazor-user-experience-prebuilt-editors"/>
    <content type="text"><![CDATA[<p><span class="featured">These editor-like components can help you improve the user experience of your Blazor application, with settings and customizations that adapt to the scenario you need.</span></p><p>If you have developed projects in Blazor, you&rsquo;ve likely had to create some kind of form using Blazor controls.</p><p>Although the platform provides native components such as <code>InputText</code>, <code>InputNumber</code> or <code>InputDate</code>, during development we realize we need specialized components to allow displaying interactive calendars, color pickers or rating controls.</p><p>In these cases, the prebuilt controls from the Progress Telerik UI for <a target="_blank" href="https://www.telerik.com/blazor-ui">Blazor library</a> can help us significantly by providing advanced editor components that drastically improve the user experience, without you having to write additional code. Let&rsquo;s take a closer look at how they can help!</p><h2 id="comparing-native-components-vs.-telerik-editors">Comparing Native Components vs. Telerik Editors</h2><p>Blazor offers a number of basic input components, such as:</p><ul><li><code>InputText</code> for text fields</li><li><code>InputNumber</code> for basic numeric fields</li><li><code>InputDate</code> for date selection</li><li><code>InputSelect</code> for dropdown lists</li><li><code>InputCheckbox</code> for checkboxes</li><li><code>InputTextArea</code> for multi-line text areas</li></ul><p>Although the above components serve their purpose for basic scenarios, they lack features that are necessary when building serious, functional applications, such as applying custom visual formatting, input masks, autocomplete, among others.</p><p>On the other hand, the category of <strong>Editors</strong> in Telerik UI for Blazor includes more than 20 specialized components that are not available natively for Blazor, including:</p><ul><li><code>TelerikColorPicker</code>: Color picker with palette and HSV gradient</li><li><code>TelerikRating</code>: Component for entering a configurable star rating</li><li><code>TelerikSignature</code>: Allows capturing digital signatures in base64 format</li><li><code>TelerikAutoComplete</code>: Search with suggestions as the user types</li><li><code>TelerikMaskedTextBox</code>: Text boxes with masks for phone numbers, cards, etc.</li><li><code>TelerikDateRangePicker</code>: Date range selection</li></ul><p>The above components provide a way to build forms and applications more quickly, since otherwise you would have to build them from scratch or resort to external JavaScript libraries that require interop that can be somewhat complex.</p><p>There are some additional reasons why it&rsquo;s convenient to use Telerik components. First, all editors integrate seamlessly with Blazor&rsquo;s form validation system.</p><p>Additionally, Telerik components adhere to accessibility standards without you having to configure anything else. They also have full support for different cultures, date formats, currencies and RTL direction.</p><h2 id="creating-a-form-using-telerik-for-blazor-ui-editors">Creating a Form Using Telerik for Blazor UI Editors</h2><p>Let&rsquo;s look at the benefits of the Telerik editors by creating a user profile form to see their capabilities.</p><h3 id="creating-a-project-with-telerik-editors-for-blazor">Creating a Project with Telerik Editors for Blazor</h3><p>Let&rsquo;s start by creating a Blazor project using the <strong>Blazor Web App</strong> template. We&rsquo;ll select an <strong>Interactive render mode</strong> of <strong>Server</strong> and <strong>Interactivity location</strong> of <strong>Global</strong>.</p><p>To install the Telerik components, you can use the <a target="_blank" href="https://www.telerik.com/blazor-ui/documentation/getting-started/web-app#set-up-telerik-development-environment">prebuilt Telerik template</a> and follow the quick-start guide, or, if you want to add the components to an existing project, you can also do so <a target="_blank" href="https://www.telerik.com/blazor-ui/documentation/getting-started/workflow-details">by following this guide</a>.</p><p>Now let&rsquo;s move on to creating a data model to bind to the UI components.</p><h3 id="creating-a-data-model">Creating a Data Model</h3><p>We&rsquo;ll create a data model that allows us to build a logical representation of a user&rsquo;s profile. For this, we&rsquo;ll create a class called <code>UserProfile</code> that will look like the following:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserProfile</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> FullName <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">string</span><span class="token punctuation">.</span>Empty<span class="token punctuation">;</span>
    <span class="token keyword">public</span> DateTime<span class="token operator">?</span> BirthDate <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span><span class="token operator">?</span> Age <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> FavoriteColor <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token string">"rgb(33, 150, 243)"</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">double</span> SatisfactionRating <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> Signature <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">string</span><span class="token punctuation">.</span>Empty<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The model above reflects properties characteristic of a user profile, such as <code>FullName</code>, <code>BirthDate</code> and <code>Age</code>. Additionally, we added some extra properties to represent favorite color, satisfaction rating and signature.</p><h3 id="building-a-form-page-using-prebuilt-blazor-controls">Building a Form Page Using Prebuilt Blazor Controls</h3><p>Let&rsquo;s create a page so a user can enter their user profile data. We&rsquo;ll do this in parts so you can see the power of the Blazor components.</p><p>First, let&rsquo;s create a component called <code>UserProfileForm.razor</code>, where we&rsquo;ll start by defining the overall structure of the component, such as the route from which it will be accessed, the title, among other things:</p><pre class=" language-xml"><code class="prism  language-xml">@page "/user-profile"
@using UserProfileDemo.Models
@rendermode InteractiveServer

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>PageTitle</span><span class="token punctuation">&gt;</span></span>User Profile<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>PageTitle</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>User Profile Form<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-muted mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    Fill in your profile information using the enhanced editor controls below.
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>Now, let&rsquo;s analyze the integration of the Telerik components into the form.</p><h3 id="using-teleriktextbox-as-text-inputs">Using TelerikTextBox as Text Inputs</h3><p>The first component we will add is a <code>TelerikTextBox</code>, which will be used to get the user&rsquo;s name. Although at first glance it may seem similar to a native <code>InputText</code>, it has additional features such as a built-in visual placeholder and prebuilt applicable styles that are consistent throughout the application.</p><p>This is how the section looks:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-8<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Full Name<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikTextBox</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@Profile.FullName<span class="token punctuation">"</span></span>
                                    <span class="token attr-name">Placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Enter your full name<span class="token punctuation">"</span></span>
                                    <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

@code {
    private UserProfile Profile { get; set; } = new();
}
</code></pre><p>The result of the execution is the following:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/telerik-textbox-demo.gif?sfvrsn=d78086b_2" alt="Telerik TextBox component in action" /></p><p>In the code above, we can see how using properties such as <code>@bind-value</code>, <code>Placeholder</code> and <code>Width</code> facilitates creating intuitive UIs without having to add extra code.</p><h3 id="selecting-dates-with-the-telerikdatepicker">Selecting Dates with the TelerikDatePicker</h3><p>The next component we will analyze is the <code>TelerikDatePicker</code>. Blazor offers a native control called <code>InputDate</code>; however, it does not provide the best user experience.</p><p>The Telerik component offers a full visual calendar with month and year navigation, customizable formatting, the ability to disable specific dates, programmatic focus, the ability to specify an initial view, among many other features.</p><p>Its implementation looks like this:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Birth Date<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikDatePicker</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@Profile.BirthDate<span class="token punctuation">"</span></span>
                       <span class="token attr-name">Format</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>dd/MM/yyyy<span class="token punctuation">"</span></span>
                       <span class="token attr-name">Min</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@MinDate<span class="token punctuation">"</span></span>
                       <span class="token attr-name">Max</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@MaxDate<span class="token punctuation">"</span></span>
                       <span class="token attr-name">Placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Select your birth date<span class="token punctuation">"</span></span>
                       <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

@code {
    private DateTime MinDate { get; set; } = new DateTime(1900, 1, 1);
    private DateTime MaxDate { get; set; } = DateTime.Today;
}
</code></pre><p>With the above code, we&rsquo;ve bound the picker value to a property with <code>@bind-value</code>, as well as specified a format for the date, a range of valid dates with <code>Min</code> and <code>Max</code>, a placeholder and a width. The result is the following:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/telerik-datepicker-date-selection.gif?sfvrsn=1824ed03_2" alt="User selecting a date with Telerik DatePicker control" /></p><p>Using the component helps provide a consistent visual style throughout the application, rather than relying on each browser&rsquo;s styles.</p><h3 id="adding-numeric-fields-using-the-teleriknumerictextbox">Adding Numeric Fields Using the TelerikNumericTextBox</h3><p>Another component we can use to accept number inputs is the <code>TelerikNumericTextBox</code>. It is much more powerful than a <code>InputNumber</code>, allowing you to define numeric formats, specify the number of decimal places, enable a clear button, among other features.</p><p>Here&rsquo;s an example of its use:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Age<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikNumericTextBox</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@Profile.Age<span class="token punctuation">"</span></span>
                           <span class="token attr-name">Min</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span>
                           <span class="token attr-name">Max</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>120<span class="token punctuation">"</span></span>
                           <span class="token attr-name">Step</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span>
                           <span class="token attr-name">Format</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>N0<span class="token punctuation">"</span></span>
                           <span class="token attr-name">Placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Enter your age<span class="token punctuation">"</span></span>
                           <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>The component in action looks as follows:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/telerik-numerictextbox-input-demo.gif?sfvrsn=3bc8946b_2" alt="Telerik NumericTextBox displaying numeric input and increment buttons" /></p><h3 id="selecting-colors-thanks-to-the-telerikcolorpicker">Selecting Colors Thanks to the TelerikColorPicker</h3><p>Now let&rsquo;s talk about some components that don&rsquo;t have a native equivalent in Blazor. The first of these is the <code>TelerikColorPicker</code>, which allows selecting a color using a visual picker, in addition to including a predefined color palette and an HSV canvas. This enables precise color selections.</p><p>The implementation looks similar to the following:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Favorite Color<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikColorPicker</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@Profile.FavoriteColor<span class="token punctuation">"</span></span>
                            <span class="token attr-name">ValueFormat</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ColorFormat.Rgb<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ms-3 align-middle<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            Selected: <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>@Profile.FavoriteColor<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>In the code above we specify that the value will be stored in RGB format. The result of running it is the following:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/telerik-colorpicker-precision.gif?sfvrsn=1441eaf7_2" alt="Selecting an exact color with Telerik ColorPicker" /></p><p>Another thing I want to highlight is the ease of use of the Telerik UI for Blazor components, since you can see that by defining a couple of parameters we have a fully functional implementation. This avoided the need to use JavaScript interoperability or an external library.</p><h3 id="evaluating-satisfaction-with-the-telerikrating">Evaluating Satisfaction with the TelerikRating</h3><p>Another component that has no native equivalent, but is certainly required in a large number of apps, is <code>TelerikRating</code>, which allows the user to provide a rating via a visual star system. Its use is quite simple:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Satisfaction Level<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikRating</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@Profile.SatisfactionRating<span class="token punctuation">"</span></span>
                       <span class="token attr-name">Max</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>5<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ms-2 text-muted<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>(@Profile.SatisfactionRating / 5)<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>In the code above, we use the <code>Max</code> parameter to indicate the maximum number of stars. One advantage of the component is that its value will be updated automatically when clicking on a star. It also has built-in keyboard support and accessibility. Let&rsquo;s see the result:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/telerik-rating-star-control.gif?sfvrsn=91869af8_2" alt="TelerikRating star control displaying selectable stars" /></p><p>If we had wanted to create the component manually, we would probably have had to handle SVG files, events and accessibility logic.</p><h3 id="displaying-the-form-result">Displaying the Form Result</h3><p>To complete the form, we are going to add a couple of buttons of type <code>TelerikButton</code>, as well as a panel to show the summary of the selected data:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>d-flex gap-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikButton</span> <span class="token attr-name">OnClick</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@SubmitProfile<span class="token punctuation">"</span></span>
                   <span class="token attr-name">ThemeColor</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@ThemeConstants.Button.ThemeColor.Primary<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        Save Profile
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>TelerikButton</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikButton</span> <span class="token attr-name">OnClick</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@ClearForm<span class="token punctuation">"</span></span>
                   <span class="token attr-name">ThemeColor</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@ThemeConstants.Button.ThemeColor.Base<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        Clear
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>TelerikButton</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
...
@code {
    ...

    private bool ShowSummary { get; set; }
    private void SubmitProfile()
    {
        ShowSummary = true;
    }

    private void ClearForm()
    {
        Profile = new UserProfile();
        ShowSummary = false;
    }
}
</code></pre><p>Additionally, we will add a side column in which we will show the summary when the user clicks the <strong>Save Profile</strong> button:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-8<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        ...

    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        @if (ShowSummary)
        {
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm border-success<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-header bg-success text-white<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Profile Summary<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Name:<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span> @Profile.FullName<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Birth Date:<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span> @Profile.BirthDate?.ToString("dd/MM/yyyy")<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Age:<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span> @Profile.Age<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Favorite Color:<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>d-inline-block rounded-circle ms-2<span class="token punctuation">"</span></span><span class="token style-attr language-css"><span class="token attr-name">
                              <span class="token attr-name">style</span></span><span class="token punctuation">="</span><span class="token attr-value"><span class="token property">width</span><span class="token punctuation">:</span> <span class="token number">20</span>px<span class="token punctuation">;</span> <span class="token property">height</span><span class="token punctuation">:</span> <span class="token number">20</span>px<span class="token punctuation">;</span> <span class="token property">background-color</span><span class="token punctuation">:</span> <span class="token atrule"><span class="token rule">@Profile</span>.FavoriteColor<span class="token punctuation">;</span></span> <span class="token property">vertical-align</span><span class="token punctuation">:</span> middle<span class="token punctuation">;</span></span><span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ms-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@Profile.FavoriteColor<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Satisfaction:<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span> @Profile.SatisfactionRating / 5<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
                    @if (!string.IsNullOrEmpty(Profile.Signature))
                    {
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>Signature:<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@Profile.Signature<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>User signature<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>img-fluid border rounded<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                    }
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        }
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>The code above allows us to validate that the data binding between controls and properties works correctly, as well as to demonstrate how easy it is to obtain information from the form using Telerik components:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/telerik-blazor-prebuilt-editors-demo.gif?sfvrsn=625ec2a3_2" alt="Final demo of Telerik Blazor prebuilt editors interface" /></p><p>With this implementation, we have created a form that allows users to enter information quickly and reliably, thanks to the Telerik for Blazor controls.</p><h2 id="conclusion">Conclusion</h2><p>Throughout this article, you&rsquo;ve been able to learn first-hand about some Telerik editor-like components that can help you improve the user experience. These components offer settings and customizations that adapt to any type of application, and they are constantly updated.</p><p>Another point to highlight is that the components&rsquo; documentation is quite comprehensive, allowing you to learn all their features in detail. It&rsquo;s time to improve your users&rsquo; experience by using these components.</p><p><a target="_blank" href="https://www.telerik.com/try/ui-for-blazor" class="Btn">Try Telerik UI for Blazor</a></p><img src="https://feeds.telerik.com/link/10827/17539504.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:02f17065-86e8-4282-93fc-db81fc349493</id>
    <title type="text">Better Auth with Nuxt and SQLite</title>
    <summary type="text">This unofficial Better Auth Nuxt demo should allow you to integrate your preferred database. It uses Tailwind 4, Nuxt 4, latest shadcn-vue, page protection and SQLite for login.</summary>
    <published>2026-11-20T15:47:15Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Jonathan Gamble </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17536335/better-auth-nuxt-sqlite"/>
    <content type="text"><![CDATA[<p><span class="featured">This unofficial Better Auth Nuxt demo should allow you to integrate your preferred database. It uses Tailwind 4, Nuxt 4, latest shadcn-vue, page protection and SQLite for login.</span></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image.png?sfvrsn=d7e40631_2" alt="Better Auth unofficial demo to showcase better-auth features and capabilities" /></p><p>The official <a target="_blank" href="https://github.com/nuxt-modules/better-auth">Better Auth Nuxt</a> repo does not seem to work correctly for me, and it&rsquo;s based on older Nuxt, Tailwind and <a target="_blank" href="https://www.shadcn-vue.com/docs/installation/nuxt">shadcn-vue</a>. I have updated it, added features and fixed security bugs allowing you to use whatever Better Auth <a target="_blank" href="https://better-auth.com/docs/adapters/mysql">database integrations</a> you like.</p><h2 id="tldr">TL;DR</h2><p>This demo uses <a target="_blank" href="https://tailwindcss.com/docs/installation/framework-guides/nuxt">Tailwind 4</a>, <a target="_blank" href="https://nuxt.com/">Nuxt 4</a>, latest <a target="_blank" href="https://www.shadcn-vue.com/docs/installation/nuxt">shadcn-vue</a>, has page protection, allows you to change your password and does not suffer from client loading problems. You log in using <a target="_blank" href="https://sqlite.org/">SQLite</a>, the session is automatically saved, and you can change your password and generate a password reset link.</p><h2 id="setup">Setup</h2><h3 id="nuxt-4">Nuxt 4</h3><p>First, generate a new Nuxt 4 repo.</p><pre class=" language-bash"><code class="prism  language-bash"><span class="token function">npm</span> create nuxt@latest
</code></pre><h3 id="tailwind">Tailwind</h3><p>Follow official instructions to install <a target="_blank" href="https://tailwindcss.com/docs/installation/framework-guides/nuxt">Tailwind 4</a>.</p><p>⚠️ DO NOT USE <a target="_blank" href="https://tailwindcss.nuxtjs.org/">Nuxt Tailwind Module</a> directly.</p><p>But, install it manually:</p><pre class=" language-bash"><code class="prism  language-bash"><span class="token function">npm</span> i -D @nuxtjs/tailwindcss
</code></pre><h3 id="vue-shadcn">Vue ShadCN</h3><p>Configure <a target="_blank" href="https://www.shadcn-vue.com/docs/installation/nuxt">ShadCN Vue for Nuxt</a>. You will need to install all components manually that you need.</p><pre class=" language-bash"><code class="prism  language-bash">npx shadcn-vue@latest add button
</code></pre><p> There is an error with the <code>all</code> flag, as it will try to install old modules. Unfortunately, the only work around is to install the components manually.</p><pre class=" language-bash"><code class="prism  language-bash">npx shadcn-vue@latest add --all
</code></pre><h3 id="better-auth">Better Auth</h3><p>Follow the <a target="_blank" href="https://better-auth.com/docs/installation">installation guide</a>. Here is a quick version.</p><p>Install the package. We will use <code>better-auth/vue</code>.</p><pre class=" language-bash"><code class="prism  language-bash"><span class="token function">npm</span> i better-auth
</code></pre><p>Generate config.</p><pre class=" language-bash"><code class="prism  language-bash">npx auth@latest generate
</code></pre><p>We will generate library files in a following section.</p><h3 id="install-temp-database">Install Temp Database</h3><p>Fastest <a target="_blank" href="https://github.com/WiseLibs/better-sqlite3">SQLite</a> in Node.js.</p><pre class=" language-bash"><code class="prism  language-bash"><span class="token function">npm</span> i better-sqlite3
</code></pre><h2 id="env">.env</h2><p>Setup your config.</p><pre class=" language-bash"><code class="prism  language-bash">BETTER_AUTH_URL<span class="token operator">=</span>http://localhost:3000 <span class="token comment"># Base URL of your app</span>
</code></pre><h2 id="nuxt-config">Nuxt Config</h2><p>Create the catch all server route.</p><pre class=" language-tsx"><code class="prism  language-tsx">// server/api/auth/[...all].ts

import { auth } from "~/lib/auth";

export default defineEventHandler((event) =&gt; {
return auth.handler(toWebRequest(event));
});
</code></pre><p>This will handle all authentication server requests.</p><h3 id="libauth-client.ts">lib/auth-client.ts</h3><p>Let&rsquo;s import the reusable client functions.</p><pre class=" language-tsx"><code class="prism  language-tsx">import { createAuthClient } from "better-auth/vue";

export const authClient = createAuthClient();

export const {
signIn,
signOut,
signUp,
useSession,
requestPasswordReset,
resetPassword,
changePassword
} = authClient;
</code></pre><h3 id="libauth.ts">lib/auth.ts</h3><p>Generate a better auth instance.</p><pre class=" language-tsx"><code class="prism  language-tsx">import Database from "better-sqlite3";
import { betterAuth } from "better-auth";

export const auth = betterAuth({
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:3000",
database: new Database("./db.sqlite"),
emailAndPassword: {
enabled: true,
async sendResetPassword(url, user) {
console.log("Reset password url:", url);
},
},
});
</code></pre><p> You must config an email server later to send emails, for now you can just print the URL.</p><p> Our database will the the file <code>db.sqlite</code>. It will <em>NOT</em> persist when deployed, so you must you a different hosted database. This is for testing on</p><p><strong>Repo:</strong> <a target="_blank" href="https://github.com/jdgamble555/nuxt-better-auth-example">GitHub</a></p><h3 id="protect-your-pages">Protect Your Pages</h3><pre class=" language-tsx"><code class="prism  language-tsx">// middleware/auth.globals.ts

export default defineNuxtRouteMiddleware(async (to, from) =&gt; {
const session = await $fetch("/api/auth/get-session", {
headers: useRequestHeaders(["cookie"]),
}).catch(() =&gt; null);

const authPages = ["/sign-in", "/sign-up", "/forget-password", "/reset-password"];
const protectedPages = ["/dashboard", "/change-password"];

if (!session) {
if (protectedPages.includes(to.path)) {
return navigateTo("/");
}
}

if (session &amp;&amp; authPages.includes(to.path)) {
return navigateTo("/dashboard");
}
});
</code></pre><p> We don&rsquo;t want login pages to be seen when logged-in, and we don&rsquo;t want login-protected pages to be seen without a session. Our server auth handles these cookies and paths for us!</p><h3 id="change-password">Change Password</h3><pre class=" language-html"><code class="prism  language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ts<span class="token punctuation">"</span></span> <span class="token attr-name">setup</span><span class="token punctuation">&gt;</span></span><span class="token script language-javascript">
<span class="token keyword">import</span> <span class="token punctuation">{</span> changePassword <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"~/lib/auth-client.js"</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> router <span class="token operator">=</span> <span class="token function">useRouter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> currentPassword <span class="token operator">=</span> <span class="token function">ref</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> newPassword <span class="token operator">=</span> <span class="token function">ref</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> confirmPassword <span class="token operator">=</span> <span class="token function">ref</span><span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> handleChangePassword <span class="token operator">=</span> <span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>confirmPassword<span class="token punctuation">.</span>value <span class="token operator">!==</span> newPassword<span class="token punctuation">.</span>value<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"Please enter the same password in both fields"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">await</span> <span class="token function">changePassword</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    currentPassword<span class="token punctuation">:</span> currentPassword<span class="token punctuation">.</span>value<span class="token punctuation">,</span>
    newPassword<span class="token punctuation">:</span> newPassword<span class="token punctuation">.</span>value<span class="token punctuation">,</span>
    fetchOptions<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token function">onSuccess</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"Password changed successfully"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        router<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token string">"/dashboard"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token function">onError</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">alert</span><span class="token punctuation">(</span>context<span class="token punctuation">.</span>error<span class="token punctuation">.</span>message<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>h-screen flex justify-center items-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Card</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mx-auto max-w-sm<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardHeader</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardTitle</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-2xl<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Change Password<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardTitle</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardDescription</span>
          <span class="token punctuation">&gt;</span></span>Enter your current password and choose a new one<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardDescription</span>
        <span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardHeader</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardContent</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>form</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>grid gap-4<span class="token punctuation">"</span></span> <span class="token attr-name">@submit.prevent</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>handleChangePassword<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>grid gap-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Label</span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>current-password<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Current Password<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Label</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Input</span>
              <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>current-password<span class="token punctuation">"</span></span>
              <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span>
              <span class="token attr-name">autocomplete</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>current-password<span class="token punctuation">"</span></span>
              <span class="token attr-name">required</span>
              <span class="token attr-name">v-model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>currentPassword<span class="token punctuation">"</span></span>
              <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Current Password<span class="token punctuation">"</span></span>
            <span class="token punctuation">/&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>grid gap-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Label</span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>new-password<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>New Password<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Label</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Input</span>
              <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>new-password<span class="token punctuation">"</span></span>
              <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span>
              <span class="token attr-name">autocomplete</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>new-password<span class="token punctuation">"</span></span>
              <span class="token attr-name">required</span>
              <span class="token attr-name">v-model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>newPassword<span class="token punctuation">"</span></span>
              <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>New Password<span class="token punctuation">"</span></span>
            <span class="token punctuation">/&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>grid gap-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Label</span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>confirm-password<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Confirm Password<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Label</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Input</span>
              <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>confirm-password<span class="token punctuation">"</span></span>
              <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span>
              <span class="token attr-name">autocomplete</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>new-password<span class="token punctuation">"</span></span>
              <span class="token attr-name">required</span>
              <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Confirm Password<span class="token punctuation">"</span></span>
              <span class="token attr-name">v-model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>confirmPassword<span class="token punctuation">"</span></span>
            <span class="token punctuation">/&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Button</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>w-full<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Change Password<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Button</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>form</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardContent</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Card</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
</code></pre><p> We import our <code>auth-client</code> functions to perform the client function for us. We <em>MUST</em> use a <code>form</code> to prevent warnings in Chrome, which is good practice anyway.</p><h3 id="dashboard">Dashboard</h3><pre class=" language-html"><code class="prism  language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">setup</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ts<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token script language-javascript">
<span class="token keyword">import</span> <span class="token punctuation">{</span> signOut <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"~/lib/auth-client"</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> router <span class="token operator">=</span> <span class="token function">useRouter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> <span class="token punctuation">{</span> data<span class="token punctuation">:</span> user <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">useAsyncData</span><span class="token punctuation">(</span><span class="token string">"accounts"</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
  <span class="token function">useAuth</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">getSession</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> res<span class="token punctuation">.</span>data<span class="token operator">?</span><span class="token punctuation">.</span>user<span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span>
    <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>min-h-[80vh] flex items-center justify-center overflow-hidden no-visible-scrollbar px-6 md:px-0<span class="token punctuation">"</span></span>
  <span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Card</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>w-87.5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardHeader</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardTitle</span><span class="token punctuation">&gt;</span></span>User<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardTitle</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardHeader</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardContent</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">v-if</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>user<span class="token punctuation">"</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>flex gap-2 items-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Avatar</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>bg-gray-200<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>AvatarImage</span> <span class="token attr-name">:src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>user.image || <span class="token punctuation">'</span><span class="token punctuation">'</span><span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>User profile<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>AvatarFallback</span><span class="token punctuation">&gt;</span></span>{{ user.name?.[0] }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>AvatarFallback</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Avatar</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-sm<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>{{ user.name }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-xs<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>{{ user.email }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">v-else</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>flex gap-2 items-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Skeleton</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>h-10 w-10 rounded-full<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>space-y-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Skeleton</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>h-4 w-28<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Skeleton</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>h-3 w-40<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardContent</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CardFooter</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>flex gap-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Button</span> <span class="token attr-name">as-child</span> <span class="token attr-name">variant</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>outline<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>NuxtLink</span> <span class="token attr-name">to</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/change-password<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Change Password<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>NuxtLink</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Button</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Button</span>
          <span class="token attr-name">:disabled</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>!user<span class="token punctuation">"</span></span>
          <span class="token attr-name">@click</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>
            async () =&gt; {
              await signOut();
              router.push(<span class="token punctuation">'</span>/<span class="token punctuation">'</span>);
            }
          <span class="token punctuation">"</span></span>
          <span class="token attr-name">variant</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>secondary<span class="token punctuation">"</span></span>
        <span class="token punctuation">&gt;</span></span>
          Sign Out
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Button</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>CardFooter</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Card</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>We want to load the session on the server, <em>NOT</em> on the client with a delay, like the original demo.</p><p> <code>useAuth</code> has many functions we can configure to work in any scenario. <code>useAsyncData</code> loads on the sever and hydrates to the client.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image-1.png?sfvrsn=4fa030ab_2" alt="useAuth list of functions" /></p><h3 id="forget-password">Forget Password</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script lang="ts" setup&gt;
import { requestPasswordReset } from "~/lib/auth-client.js";

const email = ref("");

const handleRequestPasswordReset = async () =&gt; {
  if (!email.value) {
    alert("Please enter your email address");
    return;
  }
  await requestPasswordReset(
    {
      email: email.value,
      redirectTo: "/reset-password",
    },
    {
      // onSuccess find the url with token in server console. For detail check requestPasswordReset section: https://www.better-auth.com/docs/authentication/email-password
      onSuccess() {
        alert("Password reset link sent to your email");
        window.location.href = "https://www.telerik.com/sign-in";
      },
      onError(context) {
        alert(context.error.message);
      },
    },
  );
};
&lt;/script&gt;

&lt;template&gt;
  &lt;div class="h-screen flex justify-center items-center"&gt;
    &lt;Card class="mx-auto max-w-sm"&gt;
      &lt;CardHeader&gt;
        &lt;CardTitle class="text-2xl"&gt;Reset Password&lt;/CardTitle&gt;
        &lt;CardDescription&gt;
          Enter your email below to reset your password
        &lt;/CardDescription&gt;
      &lt;/CardHeader&gt;
      &lt;CardContent&gt;
        &lt;div class="grid gap-4"&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;Label for="email"&gt;Email&lt;/Label&gt;
            &lt;Input
              id="email"
              type="email"
              autocomplete="email"
              placeholder="m@example.com"
              required
              v-model="email"
            /&gt;
          &lt;/div&gt;
          &lt;Button
            type="button"
            class="w-full"
            @click="handleRequestPasswordReset"
          &gt;
            Reset Password
          &lt;/Button&gt;
        &lt;/div&gt;
        &lt;div class="mt-4 text-center text-sm"&gt;
          &lt;a href="https://www.telerik.com/sign-in" class="underline"&gt;Back to Sign In &lt;/a&gt;
        &lt;/div&gt;
      &lt;/CardContent&gt;
    &lt;/Card&gt;
  &lt;/div&gt;
&lt;/template&gt;
</code></pre><p> We must configure an email server to work in production. This setup is similar to previous pages.</p><h3 id="home">Home</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script setup lang="ts"&gt;
import { useSession } from "~/lib/auth-client";

definePageMeta({
layout: "default",
});

const features = [
"Email &amp; Password",
"Organization | Teams",
"Passkeys",
"Multi Factor",
"Password Reset",
"Email Verification",
"Roles &amp; Permissions",
"Rate Limiting",
"Session Management",
];
const session = useSession();
&lt;/script&gt;

&lt;template&gt;
    &lt;div class="min-h-[80vh] flex items-center justify-center overflow-hidden no-visible-scrollbar px-6 md:px-0"&gt;
        &lt;main class="flex flex-col gap-4 row-start-2 items-center justify-center"&gt;
            &lt;div class="flex flex-col gap-1"&gt;
                &lt;h3 class="font-bold text-4xl text-black dark:text-white text-center"&gt;
                    Better Auth.
                &lt;/h3&gt;

                &lt;p class="text-center wrap-break-word text-sm md:text-base"&gt;
                    &lt;span class="inline-flex items-center gap-2"&gt;
                        &lt;span class="relative inline-block -rotate-2 pr-1 text-[0.78rem] font-black uppercase tracking-[0.16em] text-red-600/80"&gt;
                            &lt;span class="absolute left-0 right-0 top-1/2 h-0.5 -translate-y-1/2 -rotate-3 rounded-full bg-linear-to-r from-red-400 via-red-600 to-red-400 shadow-[0_0_10px_rgba(220,38,38,0.45)]" /&gt;
                            &lt;span&gt;official&lt;/span&gt;
                        &lt;/span&gt;
                        &lt;span class="inline-flex items-center rounded-full border border-blue-500/40 bg-linear-to-r from-blue-500/10 to-blue-500/10 px-2.5 py-0.5 text-[0.72rem] font-bold uppercase tracking-[0.14em] text-blue-700 shadow-sm"&gt;
                            unofficial
                        &lt;/span&gt;
                    &lt;/span&gt;
                    demo to showcase
                    &lt;a
href="https://better-auth.com"
target="_blank"
className="italic underline"
&gt;better-auth
                    &lt;/a&gt;
                    features and capabilities. &lt;br /&gt;
                &lt;/p&gt;

                &lt;div class="flex flex-col gap-3 pt-2 flex-wrap"&gt;
                    &lt;div class="border-y py-2 border-dotted bg-secondary/60 opacity-80"&gt;
                        &lt;div class="text-xs flex items-center gap-2 justify-center text-muted-foreground"&gt;
                            &lt;span class="text-center"&gt;
                                All features on this demo are Implemented with Better Auth without
                                any custom backend code
                            &lt;/span&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="flex gap-2 justify-center flex-wrap"&gt;
                        &lt;div v-for="feature in features" :key="feature"&gt;
                            &lt;span
                                class="border-b pb-1 text-muted-foreground text-xs cursor-pointer hover:text-foreground duration-150 ease-in-out transition-all hover:border-foreground flex items-center gap-1"&gt;{{
                                    feature }}
                            &lt;/span&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="flex items-center gap-2 mt-2 mx-auto"&gt;
                    &lt;NuxtLink to="/sign-in" v-if="!session?.data"&gt;
                        &lt;Button variant="outline" class="rounded-none"&gt;
                            Sign In
                        &lt;/Button&gt;
                    &lt;/NuxtLink&gt;
                    &lt;NuxtLink to="/dashboard" v-if="session?.data"&gt;
                        &lt;Button variant="outline" class="rounded-none"&gt;
                            Dashboard
                        &lt;/Button&gt;
                    &lt;/NuxtLink&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/main&gt;
    &lt;/div&gt;
&lt;/template&gt;
</code></pre><p> Nothing special here, except for checking for a <code>session</code>.</p><h3 id="reset-password">Reset Password</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script lang="ts" setup&gt;
import { resetPassword } from "~/lib/auth-client.js";

const confirmPassword = ref("");
const password = ref("");

const handleResetPassword = async () =&gt; {
  if (confirmPassword.value !== password.value) {
    alert("Please enter same passwords");
    return;
  }

  await resetPassword({
    newPassword: password.value,
    fetchOptions: {
      onSuccess(context) {
        window.location.href = "https://www.telerik.com/sign-in";
      },
      onError(context) {
        alert(context.error.message);
      },
    },
  });
};
&lt;/script&gt;

&lt;template&gt;
  &lt;div class="h-screen flex justify-center items-center"&gt;
    &lt;Card class="mx-auto max-w-sm"&gt;
      &lt;CardHeader&gt;
        &lt;CardTitle class="text-2xl"&gt;Reset Password&lt;/CardTitle&gt;
        &lt;CardDescription&gt;Enter your new password below&lt;/CardDescription&gt;
      &lt;/CardHeader&gt;
      &lt;CardContent&gt;
        &lt;form class="grid gap-4" @submit.prevent="handleResetPassword"&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;Label for="new-password"&gt;New Password&lt;/Label&gt;
            &lt;Input
              id="new-password"
              type="password"
              autocomplete="new-password"
              required
              v-model="password"
              placeholder="New Password"
            /&gt;
          &lt;/div&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;Label for="confirm-password"&gt;Confirm Password&lt;/Label&gt;
            &lt;Input
              id="confirm-password"
              type="password"
              autocomplete="new-password"
              required
              placeholder="Confirm Password"
              v-model="confirmPassword"
            /&gt;
          &lt;/div&gt;
          &lt;Button type="submit" class="w-full"&gt;Reset&lt;/Button&gt;
        &lt;/form&gt;
      &lt;/CardContent&gt;
    &lt;/Card&gt;
  &lt;/div&gt;
&lt;/template&gt;
</code></pre><p> Same setup as before, import our <code>resetPassword</code> function from our auth library.</p><h3 id="sign-in">Sign In</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script setup lang="ts"&gt;
import { signIn } from "~/lib/auth-client.js";

const email = ref("");
const password = ref("");
const router = useRouter();

const handleSignIn = async () =&gt; {
  await signIn.email({
    email: email.value,
    password: password.value,
    callbackURL: "/dashboard",
    fetchOptions: {
      onError(context) {
        alert(context.error.message);
      },
      onSuccess() {
        router.push("/dashboard");
      },
    },
  });
};
&lt;/script&gt;

&lt;template&gt;
  &lt;div class="h-screen flex justify-center items-center"&gt;
    &lt;Card class="mx-auto max-w-sm"&gt;
      &lt;CardHeader&gt;
        &lt;CardTitle class="text-2xl"&gt; Login &lt;/CardTitle&gt;
        &lt;CardDescription&gt;
          Enter your email below to login to your account
        &lt;/CardDescription&gt;
      &lt;/CardHeader&gt;
      &lt;CardContent&gt;
        &lt;form class="grid gap-4" @submit.prevent="handleSignIn"&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;Label for="email"&gt;Email&lt;/Label&gt;
            &lt;Input
              id="email"
              type="email"
              autocomplete="email"
              placeholder="m@example.com"
              v-model="email"
              required
            /&gt;
          &lt;/div&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;div class="flex items-center"&gt;
              &lt;Label for="password"&gt;Password&lt;/Label&gt;
              &lt;a
                href="https://www.telerik.com/forgot-password"
                class="ml-auto inline-block text-sm underline"
              &gt;
                Forgot your password?
              &lt;/a&gt;
            &lt;/div&gt;
            &lt;Input
              id="password"
              type="password"
              autocomplete="current-password"
              placeholder="password"
              v-model="password"
              required
            /&gt;
          &lt;/div&gt;
          &lt;Button type="submit" class="w-full"&gt; Login &lt;/Button&gt;
        &lt;/form&gt;
        &lt;div class="mt-4 text-center text-sm"&gt;
          Don't have an account?
          &lt;a href="https://www.telerik.com/sign-up" class="underline"&gt; Sign up &lt;/a&gt;
        &lt;/div&gt;
      &lt;/CardContent&gt;
    &lt;/Card&gt;
  &lt;/div&gt;
&lt;/template&gt;
</code></pre><p> Manually forward router to <code>/dashboard</code> upon success.</p><h3 id="sign-up">Sign Up</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script lang="ts" setup&gt;
import { signUp } from "~/lib/auth-client.js";

const firstName = ref("");
const lastName = ref("");
const email = ref("");
const password = ref("");

const handleSignUp = async () =&gt; {
  const user = {
    firstName: firstName.value,
    lastName: lastName.value,
    email: email.value,
    password: password.value,
  };
  await signUp.email({
    email: user.email,
    password: user.password,
    name: `${user.firstName} ${user.lastName}`,
    callbackURL: "/",
    fetchOptions: {
      onError(context) {
        alert(context.error.message);
      },
      onSuccess() {
        useRouter().push("/dashboard");
      },
    },
  });
};
&lt;/script&gt;

&lt;template&gt;
  &lt;div class="h-screen flex justify-center items-center"&gt;
    &lt;Card class="mx-auto max-w-sm"&gt;
      &lt;CardHeader&gt;
        &lt;CardTitle class="text-xl"&gt;Sign Up&lt;/CardTitle&gt;
        &lt;CardDescription&gt;
          Enter your information to create an account
        &lt;/CardDescription&gt;
      &lt;/CardHeader&gt;
      &lt;CardContent&gt;
        &lt;form class="grid gap-4" @submit.prevent="handleSignUp"&gt;
          &lt;div class="grid grid-cols-2 gap-4"&gt;
            &lt;div class="grid gap-2"&gt;
              &lt;Label for="first-name"&gt;First name&lt;/Label&gt;
              &lt;Input
                id="first-name"
                autocomplete="given-name"
                placeholder="Max"
                required
                v-model="firstName"
              /&gt;
            &lt;/div&gt;
            &lt;div class="grid gap-2"&gt;
              &lt;Label for="last-name"&gt;Last name&lt;/Label&gt;
              &lt;Input
                id="last-name"
                autocomplete="family-name"
                placeholder="Robinson"
                required
                v-model="lastName"
              /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;Label for="email"&gt;Email&lt;/Label&gt;
            &lt;Input
              id="email"
              type="email"
              autocomplete="email"
              placeholder="m@example.com"
              required
              v-model="email"
            /&gt;
          &lt;/div&gt;
          &lt;div class="grid gap-2"&gt;
            &lt;Label for="password"&gt;Password&lt;/Label&gt;
            &lt;Input
              id="password"
              type="password"
              autocomplete="new-password"
              v-model="password"
            /&gt;
          &lt;/div&gt;
          &lt;Button type="submit" class="w-full"&gt;Create an account&lt;/Button&gt;
        &lt;/form&gt;
        &lt;div class="mt-4 text-center text-sm"&gt;
          Already have an account?
          &lt;a href="https://www.telerik.com/sign-in" class="underline"&gt; Sign in &lt;/a&gt;
        &lt;/div&gt;
      &lt;/CardContent&gt;
    &lt;/Card&gt;
  &lt;/div&gt;
&lt;/template&gt;
</code></pre><p> We use <code>alert</code> for errors, but this is easily configurable.</p><h2 id="bonus">Bonus</h2><p>We can easily use any <a target="_blank" href="https://better-auth.com/docs/adapters/other-relational-databases">database integration</a> we like.</p><h3 id="postgres">Postgres</h3><p><a target="_blank" href="https://better-auth.com/docs/adapters/postgresql">Postgres</a>:</p><pre class=" language-tsx"><code class="prism  language-tsx">export const auth = betterAuth({
  database: new Pool({
    connectionString: "postgres://user:password@localhost:5432/database",
  }),
});
</code></pre><p><a target="_blank" href="https://better-auth.com/docs/adapters/mysql">MySQL</a>:</p><pre class=" language-tsx"><code class="prism  language-tsx">import { betterAuth } from "better-auth";
import { createPool } from "mysql2/promise";
export const auth = betterAuth({
  database: createPool({
    host: "localhost",
    user: "root",
    password: "password",
    database: "database",
    timezone: "Z", // Important to ensure consistent timezone values
  }),
});
</code></pre><p>Now, go build the rest of your app!</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image-2.png?sfvrsn=31bef6bd_2" alt="Login screen with email and password fields" /></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image-3.png?sfvrsn=660b891a_2" alt="Sign up screen with first name, last name, email, password fields" /></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image-4.png?sfvrsn=23763786_2" alt="reset password screen with email field" /></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image-5.png?sfvrsn=1c099547_2" alt="User account screen with first and last name, email, avatar, and buttons for change password and sign out" /></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-11/image-6.png?sfvrsn=f9a182df_2" alt="Change Password screen with fields for current, new and confirm password" /></p><p><strong>Repo:</strong> <a target="_blank" href="https://github.com/jdgamble555/nuxt-better-auth-example">GitHub</a></p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">Best Graph Databases in 2026</h4></div><div class="col-8"><p class="u-fs16 u-mb0">One developer weighs <a target="_blank" href="https://www.telerik.com/blogs/best-graph-databases-2026">pros and cons of graph databases</a> and shares his insights into what works best for various use cases.</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17536335.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:e59fcc63-bf98-42f0-91ca-eb6ff8440588</id>
    <title type="text">Generic Components for Vue 3</title>
    <summary type="text">Generic components in Vue let you reuse a list without specifying what it will contain. Let’s see.</summary>
    <published>2026-11-19T14:35:54Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Marina Mosti </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17535589/generic-components-vue-3"/>
    <content type="text"><![CDATA[<p><span class="featured">Generic components in Vue let you reuse a list without specifying what it will contain. Let&rsquo;s build one with <code>&lt;script setup lang="ts" generic&gt;</code>.</span></p><p>A while back I wrote <a target="_blank" href="https://www.telerik.com/blogs/vue-3-typescript-jump-start">Vue 3 with TypeScript Jump-Start</a>, which covered the pieces you need to be productive on day one. Typing props, typing emits, <code>Ref&lt;T&gt;</code> and getting your editor to stop lying to you. That article stopped at the point where most people stop, which is typing a component that knows exactly what it works with.</p><p>This one picks up where the types stop being concrete. Let&rsquo;s say you&rsquo;ve built a <code>&lt;UserList&gt;</code>. Then somebody needs the same list for products and then for invoices, and now you&rsquo;re staring at three near-identical components or one component whose props are typed <code>any[]</code>.</p><p>That&rsquo;s the problem generic components solve. You write the list once, and it takes on the type of whatever you hand it. The parent gets full autocomplete on the slot props, the emit payloads, everything.</p><p>Let&rsquo;s go ahead and build one!</p><h2 id="what-is-a-generic-component">What Is a Generic Component?</h2><p>A generic component is a component with a type parameter, the same idea as a generic function in TypeScript. You declare a placeholder type, use it in your props and emits, and the caller fills it in.</p><p>The syntax is a <code>generic</code> attribute on the <code>&lt;script setup&gt;</code> tag:</p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T"&gt;
&lt;/script&gt;
</code></pre><p>That <code>T</code> is now available everywhere inside the block. Whatever you can write between the angle brackets of a generic function, you can write in that attribute. You can constrain <code>T</code> with <code>extends</code>, give it a default, declare a second parameter or point at a type you imported at the top of the file.</p><p>A quick note on versions. The <code>generic</code> attribute shipped in Vue 3.3. The tooling around it got better through 3.4 and 3.5, and 3.5 is where reactive props destructure became stable and on by default. That&rsquo;s the piece that makes prop defaults pleasant on a generic component, we&rsquo;ll cover it further down.</p><h2 id="the-problem-concretely">The Problem, Concretely</h2><p>Here&rsquo;s the list component before implementing generics, written for <code>User</code> instances.</p><p><code>UserList.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts"&gt;
type User = {
  id: number
  name: string
  email: string
}

defineProps&lt;{
  items: User[]
}&gt;()

const emit = defineEmits&lt;{
  select: [user: User]
}&gt;()
&lt;/script&gt;

&lt;template&gt;
  &lt;ul&gt;
    &lt;li v-for="user in items" :key="user.id" @click="emit('select', user)"&gt;
      {{ user.name }}
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/template&gt;
</code></pre><p>Nothing wrong with this component. It&rsquo;s typed, it works, your editor helps you inside the template. The only issue is that it&rsquo;s welded to <code>User</code>.</p><p>When the product list request comes in, you have two bad options. Copy the file and swap the type, which means every fix now has to be made twice. Or loosen <code>items</code> to <code>any[]</code> and lose every bit of type safety the component had, both inside it and in the parent.</p><p>To be quite honest with you, I&rsquo;ve shipped both of these at some point, and the <code>any[]</code> version is the one that comes back to bite you later.</p><h2 id="the-same-list-generic">The Same List, Generic</h2><p><code>TypedList.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T"&gt;
defineProps&lt;{
  items: T[]
}&gt;()

const emit = defineEmits&lt;{
  select: [item: T]
}&gt;()

defineSlots&lt;{
  default(props: { item: T }): any
}&gt;()
&lt;/script&gt;

&lt;template&gt;
  &lt;ul&gt;
    &lt;li
      v-for="(item, index) in items"
      :key="index"
      @click="emit('select', item)"
    &gt;
      &lt;slot :item="item" /&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/template&gt;
</code></pre><p>Let&rsquo;s break it down. The <code>generic="T"</code> attribute introduces the type parameter. From there, <code>T</code> is just a type name you can use anywhere in the block, so <code>items: T[]</code> says &ldquo;an array of whatever this component was called with.&rdquo;</p><p>The emit declaration uses the same <code>T</code>. That&rsquo;s the part that matters, because the payload of <code>select</code> is now tied to the items you passed in, not to a type the component picked in advance.</p><p><code>defineSlots</code> is optional here (the tooling can usually work the slot prop type out from <code>&lt;slot :item="item" /&gt;</code> on its own), but I like writing it out on anything reusable. It documents the slot contract at the top of the file where a reader will actually see it, instead of leaving it buried in the template.</p><p>Now the parent:</p><p><code>Dashboard.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts"&gt;
import { ref } from 'vue'
import TypedList from './TypedList.vue'

type User = {
  id: number
  name: string
  email: string
}

const users = ref&lt;User[]&gt;([
  { id: 1, name: 'Marina', email: 'marina@myapp.com' },
  { id: 2, name: 'Alex', email: 'alex@myapp.com' },
])

const handleSelect = (user: User) =&gt; {
  console.log(user.email)
}
&lt;/script&gt;

&lt;template&gt;
  &lt;TypedList :items="users" @select="handleSelect"&gt;
    &lt;template #default="{ item }"&gt;
      {{ item.name }} ({{ item.email }})
    &lt;/template&gt;
  &lt;/TypedList&gt;
&lt;/template&gt;
</code></pre><p>Notice how nothing here declares what <code>T</code> is. TypeScript works it out from <code>:items="users"</code>, sees a <code>User[]</code>, and fills in <code>T</code> as <code>User</code> for the whole component.</p><p>The payoff shows up in two places. Inside the slot, <code>item</code> is a <code>User</code>, so <code>item.email</code> autocompletes and <code>item.emial</code> is a red squiggle. And <code>handleSelect</code> is checked against the emit, so if you typed it as <code>(product: Product)</code> you&rsquo;d get an error at the <code>@select</code> binding instead of a surprise at runtime.</p><p>Swap <code>users</code> for a <code>Product[]</code> in a different parent and everything re-infers. Same component file, no changes.</p><h2 id="constraints-and-keyof-t">Constraints and keyof T</h2><p>An unconstrained <code>T</code> means the component can&rsquo;t assume anything about the items. That&rsquo;s fine for a simple wrapper, but real components usually need something. A key for <code>v-for</code>, a label to display, a field to sort by.</p><p>You could reach for <code>extends</code> and require a shape:</p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T extends { id: string | number }"&gt;
&lt;/script&gt;
</code></pre><p>Now anything passed in has to have an <code>id</code>, and you can safely write <code>:key="item.id"</code>. Pass an array of objects without one and the parent gets an error at the binding.</p><p>That works, but it forces every caller into your naming. The version I reach for more often lets the caller pick the field, and still checks that the field exists:</p><p><code>KeyedList.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T"&gt;
defineProps&lt;{
  items: T[]
  itemKey: keyof T
  labelKey: keyof T
}&gt;()
&lt;/script&gt;

&lt;template&gt;
  &lt;ul&gt;
    &lt;li v-for="item in items" :key="String(item[itemKey])"&gt;
      {{ item[labelKey] }}
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/template&gt;
</code></pre><p>This works because of <code>keyof T</code>. The prop accepts only the names of keys that actually exist on the item type. In the parent, typing <code>item-key="</code> pops open an autocomplete list of <code>id</code>, <code>name</code>, <code>email</code>, and a typo like <code>item-key="nmae"</code> fails to compile.</p><p><code>Directory.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;template&gt;
  &lt;KeyedList :items="users" item-key="id" label-key="name" /&gt;
&lt;/template&gt;
</code></pre><p>I find this pattern most useful in table and picker components. Those are exactly the ones where you end up passing column or field names around as strings and hoping nobody renames anything.</p><p>One thing. Notice the <code>String()</code> call around <code>item[itemKey]</code>. <code>keyof T</code> accepts every key on the type, including ones holding objects or dates, and <code>:key</code> wants a string or a number. If you want to be stricter, you can filter the keys by the type of their values.</p><p>That takes a small helper, a mapped type you&rsquo;ll find in plenty of codebases, usually under a different name each time. Since <code>generic</code> can reference imported types, you can keep it out of the component:</p><p><code>types.ts</code></p><pre class=" language-typescript"><code class="prism  language-typescript"><span class="token keyword">export</span> <span class="token keyword">type</span> KeysOfType<span class="token operator">&lt;</span>T<span class="token punctuation">,</span> V<span class="token operator">&gt;</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token punctuation">[</span>K <span class="token keyword">in</span> keyof T<span class="token punctuation">]</span><span class="token operator">-</span><span class="token operator">?</span><span class="token punctuation">:</span> T<span class="token punctuation">[</span>K<span class="token punctuation">]</span> <span class="token keyword">extends</span> <span class="token class-name">V</span> <span class="token operator">?</span> K <span class="token punctuation">:</span> never
<span class="token punctuation">}</span><span class="token punctuation">[</span>keyof T<span class="token punctuation">]</span>
</code></pre><p><code>KeyedList.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script
  setup
  lang="ts"
  generic="T, K extends KeysOfType&lt;T, string | number&gt;"
&gt;
import type { KeysOfType } from './types'

defineProps&lt;{
  items: T[]
  itemKey: K
  labelKey: K
}&gt;()
&lt;/script&gt;
</code></pre><p>Say <code>User</code> grows a <code>createdAt</code> field holding a <code>Date</code>. The parent now gets this:</p><p><code>Directory.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;template&gt;
  &lt;KeyedList :items="users" item-key="id" label-key="createdAt" /&gt;
&lt;/template&gt;
</code></pre><p>The error lands on <code>label-key</code> in the parent, at the exact spot where somebody made the wrong call. <code>KeysOfType&lt;User, string | number&gt;</code> resolves to <code>'id' | 'name' | 'email'</code>, and <code>createdAt</code> simply isn&rsquo;t in it. The parent can only name fields you can actually render.</p><p>The <code>String()</code> call still has to stay in the template. While <code>T</code> is still a placeholder, TypeScript can&rsquo;t resolve that constraint. It never gets far enough to see that <code>T[K]</code> is a string or a number.</p><p>Both key props share one <code>K</code> here, which keeps the signature readable. They don&rsquo;t have to name the same field, but they are held to the same constraint. If they ever need different ones (a key that can be a number, a label that must be a string), they need a parameter each.</p><p>I usually don&rsquo;t bother with the second version. Two type parameters plus a helper type makes the component harder to read than the extra safety is worth, and a stray <code>[object Object]</code> in a list is a five-second bug to spot. But it&rsquo;s there when the component is shared widely enough to earn it.</p><h2 id="prop-defaults-on-a-generic-component">Prop Defaults on a Generic Component</h2><p>This is the part that got noticeably better in Vue 3.5. <code>withDefaults</code> has always been an odd fit here. It wraps <code>defineProps</code> in another function call, and that extra layer is where generic inference used to break down. Most of those bugs are fixed now, but it still reads like a workaround.</p><p>Reactive props destructure, stable and on by default as of 3.5, completely works around the problem. You destructure the props and use plain JavaScript default values:</p><p><code>EmptyableList.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T"&gt;
const { items, emptyMessage = 'Nothing here yet' } = defineProps&lt;{
  items: T[]
  emptyMessage?: string
}&gt;()
&lt;/script&gt;

&lt;template&gt;
  &lt;p v-if="items.length === 0"&gt;{{ emptyMessage }}&lt;/p&gt;
  &lt;ul v-else&gt;
    &lt;li v-for="(item, index) in items" :key="index"&gt;
      &lt;slot :item="item" /&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/template&gt;
</code></pre><p><code>items</code> and <code>emptyMessage</code> stay reactive after destructuring, because the compiler prepends <code>props.</code> to those names for you. Generic inference is untouched, since <code>defineProps</code> is called directly.</p><p>Big disclaimer though! And this is a whopper.</p><p>The compiler does this by rewriting the names, and it rewrites them everywhere in the block. So <code>watch(emptyMessage, ...)</code> would mean <code>watch(props.emptyMessage, ...)</code>. That reads the prop once and passes the result, which leaves <code>watch</code> holding a string it has no way to track.</p><p>The compiler catches this one and fails the build with an error telling you to pass a getter instead. Here&rsquo;s that fix:</p><p><code>EmptyableList.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T"&gt;
import { watch } from 'vue'

// ...props destructured as above

watch(() =&gt; emptyMessage, (value) =&gt; {
  console.log('changed to', value)
})
&lt;/script&gt;
</code></pre><p>The getter body is still inside <code>&lt;script setup&gt;</code>, so <code>emptyMessage</code> becomes <code>props.emptyMessage</code> there too, and now it&rsquo;s read fresh on every run.</p><p>Same rule for composables. Pass <code>() =&gt; emptyMessage</code> rather than the value. The compiler only checks <code>watch</code> and <code>toRef</code>, so that one is on you. It&rsquo;s the rule you already follow for props, just easier to forget now that they look like ordinary variables.</p><h2 id="when-inference-cant-do-it">When Inference Can&rsquo;t Do It</h2><p>Inference works when a prop carries the type in. Sometimes nothing does. Picture a select component that fetches its own options from an endpoint you pass as a string:</p><p><code>RemoteSelect.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup lang="ts" generic="T extends { id: number; label: string }"&gt;
import { ref, onMounted } from 'vue'
import type { Ref } from 'vue'

const { endpoint } = defineProps&lt;{
  endpoint: string
}&gt;()

const emit = defineEmits&lt;{
  change: [option: T]
}&gt;()

const options = ref([]) as Ref&lt;T[]&gt;
const error = ref('')

const loadOptions = async () =&gt; {
  const response = await fetch(`https://myapp.com${endpoint}`)
  if (!response.ok) {
    throw new Error('Failed to load options')
  }
  options.value = await response.json()
}

onMounted(() =&gt; {
  loadOptions().catch(() =&gt; {
    error.value = 'Could not load the options for this field.'
  })
})

const handleChange = (event: Event) =&gt; {
  const id = Number((event.target as HTMLSelectElement).value)
  const selected = options.value.find((option) =&gt; option.id === id)

  if (selected) {
    emit('change', selected)
  }
}
&lt;/script&gt;

&lt;template&gt;
  &lt;p v-if="error"&gt;{{ error }}&lt;/p&gt;
  &lt;select v-else @change="handleChange"&gt;
    &lt;option v-for="option in options" :key="option.id" :value="option.id"&gt;
      {{ option.label }}
    &lt;/option&gt;
  &lt;/select&gt;
&lt;/template&gt;
</code></pre><p>Let&rsquo;s break it down.</p><p>The constraint on <code>T</code> is what lets the template read <code>option.id</code> and <code>option.label</code> without complaint, since every option is guaranteed to have both.</p><p>I pulled <code>loadOptions</code> out into its own function so the <code>onMounted</code> callback stays synchronous. Vue does catch errors from an <code>async</code> lifecycle hook, but it sends them to the app-level error handler, not to your <code>error</code> ref. The user would sit in front of an empty select with nothing telling them why. Calling <code>.catch()</code> yourself keeps the failure where you can show it.</p><p>The typing problem is that no prop carries <code>T</code> into the component. TypeScript has nothing to work backward from, so <code>T</code> falls back to the constraint. That&rsquo;s fine inside the component, and it&rsquo;s a problem the moment an option travels back out. The <code>change</code> payload is typed as <code>{ id: number; label: string }</code> and nothing else, so a parent listening for a selected country gets none of the fields its own <code>Country</code> type has.</p><p>Vue Language Tools has an answer for this, a <a target="_blank" href="https://vuejs.org/api/sfc-script-setup.html#generics">comment directive called <code>@vue-generic</code></a> that lets the parent state the type by hand:</p><p><code>AddressForm.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;template&gt;
  &lt;!-- @vue-generic {import('@/types').Country} --&gt;
  &lt;RemoteSelect endpoint="/countries" /&gt;

  &lt;!-- @vue-generic {import('@/types').Currency} --&gt;
  &lt;RemoteSelect endpoint="/currencies" /&gt;
&lt;/template&gt;
</code></pre><p>The comment goes on the line directly above the component, and the type inside the braces is what <code>T</code> becomes for that one instance. <code>Country</code> still has to satisfy the constraint, so if your <code>Country</code> type calls its fields <code>code</code> and <code>name</code>, you&rsquo;ll get an error on the comment line rather than on the component. Worth knowing before you spend an afternoon on it.</p><p>Two more things. This is a type-checking feature from the tooling rather than something the Vue runtime knows about, so it only does anything if you&rsquo;re running <code>vue-tsc</code> or working in an editor with the Vue extension. And it&rsquo;s not the prettiest thing you&rsquo;ll write this week.</p><p>Honestly, when I hit this, I first ask whether the component should be fetching at all. Fetching outside and passing the array in as a prop gives you inference for free and a component that&rsquo;s much easier to test. Sometimes the self-contained widget really is what you want, though, and this is how you type it.</p><h2 id="when-not-to-reach-for-a-generic">When Not to Reach for a Generic</h2><p>Generics are for components that genuinely don&rsquo;t care about the shape of their data. Lists, tables, pickers, dropdowns, anything that arranges items and hands them back to a slot.</p><p>They&rsquo;re the wrong tool when your component actually does care. Say you have a <code>&lt;UserCard&gt;</code> that reads <code>user.avatarUrl</code>, falls back to initials from <code>user.firstName</code> and shows a badge when <code>user.role</code> is <code>admin</code>. That component works with users. Typing the prop as <code>User</code> says so in one word, and anyone reading the file knows what they&rsquo;re holding. Make it generic, and you&rsquo;d need a constraint listing all three fields. That&rsquo;s the same information in a form that&rsquo;s harder to read. And you&rsquo;d have to update it by hand every time the card uses one more field.</p><p>The other case I&rsquo;d skip it is when a component used in exactly one place. The type parameter is real complexity, and it only pays off across several call sites. Write it concrete, and make it generic on the day the second caller shows up.</p><h2 id="wrapping-up">Wrapping Up</h2><p>Generic components close the last real gap in Vue&rsquo;s TypeScript support. Components that work with data shapes they don&rsquo;t know in advance can now be typed properly, with one attribute. You get inferred slot props, inferred emit payloads and <code>keyof T</code> constraints that make string props check themselves.</p><p>For the details, the <a target="_blank" href="https://vuejs.org/api/sfc-script-setup.html#generics"><code>generic</code> section</a> and the <a target="_blank" href="https://vuejs.org/api/sfc-script-setup.html#defineslots"><code>defineSlots</code> section</a> of the <code>&lt;script setup&gt;</code> docs are both short and worth reading, and <a target="_blank" href="https://vuejs.org/guide/components/props.html#reactive-props-destructure">Reactive Props Destructure</a> covers the defaults behavior in full.</p><p>Happy typing!</p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">A Better v-model with defineModel</h4></div><div class="col-8"><p class="u-fs16 u-mb0"><a target="_blank" href="https://www.telerik.com/blogs/better-v-model-definemodel">Learn more about defineModel.</a> Rather than three separate pieces for a two-way bound value, defineModel gives this common Vue component pattern a single line of syntax.</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17535589.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:10773d14-6dee-4d5f-87df-744ba0bf2560</id>
    <title type="text">Build and Deploy a Dockerized NestJS Application on Google Cloud Run</title>
    <summary type="text">Build an image for a NestJS project and deploy it on Google Cloud Platform and learn common tweaks and tips for updating and improving deployed services.</summary>
    <published>2026-11-17T17:46:16Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Christian Nwamba </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17528831/build-deploy-dockerized-nestjs-application-google-cloud-run"/>
    <content type="text"><![CDATA[<p><span class="featured">Build an image for a NestJS project and deploy it on Google Cloud Platform and learn common tweaks and tips for updating and improving deployed services.</span></p><p>Containers allow us to package software and all its dependencies into a lightweight, portable unit that we can run and scale either locally or in the cloud. <a target="_blank" href="https://cloud.google.com/run">Google Cloud Run</a> is a service provided on Google Cloud Platform that allows developers to deploy and scale containers for virtually any kind of application with minimal effort.</p><p>Before running containers, we have to build images. Google Cloud Run allows us to build them in the cloud using buildpacks, or build them locally on our PC with container runtimes like <a target="_blank" href="https://www.docker.com/">Docker</a> or <a target="_blank" href="https://podman.io/">Podman</a>. This article will focus on the latter. We&rsquo;ll build an image for a <a target="_blank" href="https://nestjs.com/">NestJS</a> project and deploy it on Google Cloud Platform. We&rsquo;ll also cover common tips for updating and improving deployed services.</p><h2 id="prerequisites">Prerequisites</h2><p>This guide assumes that you&rsquo;re familiar with server-side programming in <a target="_blank" href="https://www.typescriptlang.org/">TypeScript</a> and have some familiarity with a container runtime like Docker or Podman.</p><h2 id="project-setup">Project Setup</h2><p>Let&rsquo;s start by setting up the NestJS project we&rsquo;ll be deploying. Open your terminal and run the following command:</p><pre class=" language-shell"><code class="prism  language-shell">ng new my-nest-backend
</code></pre><p>The command above uses the Nest CLI to create a project in a folder called <code>my-nest-backend</code>. Follow the prompts and accept all the defaults.</p><p>Next, let&rsquo;s install the dependencies we&rsquo;ll be needing. Run this command in your terminal:</p><pre class=" language-shell"><code class="prism  language-shell">pnpm i -save @nestjs/config 
</code></pre><p>We installed the config module to use environment variables. Later on, we&rsquo;ll show how to add and use environment variables in our deployment. For now, run this command in your terminal to create a file that will hold environment variables locally.</p><pre class=" language-shell"><code class="prism  language-shell">touch .env
</code></pre><p>Next, update the <code>.env</code> file to look like this:</p><pre class=" language-js"><code class="prism  language-js">MESSAGE<span class="token operator">=</span>dev<span class="token operator">-</span>message
</code></pre><p>Now let&rsquo;s update the contents of our <code>app.module.ts</code> file.</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Module <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/common'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> AppController <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./app.controller'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> AppService <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./app.service'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ConfigModule <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/config'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> CoreModule <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./dummy/core.module'</span><span class="token punctuation">;</span>

@<span class="token function">Module</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
imports<span class="token punctuation">:</span> <span class="token punctuation">[</span>
ConfigModule<span class="token punctuation">.</span><span class="token function">forRoot</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    isGlobal<span class="token punctuation">:</span> <span class="token keyword">true</span><span class="token punctuation">,</span>
    ignoreEnvFile<span class="token punctuation">:</span> process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>NODE_ENV <span class="token operator">===</span> <span class="token string">'production'</span><span class="token punctuation">,</span>
    envFilePath<span class="token punctuation">:</span> <span class="token punctuation">[</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>NODE_ENV <span class="token operator">!==</span> <span class="token string">'production'</span> <span class="token operator">?</span> <span class="token string">'.env'</span> <span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
CoreModule<span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">,</span>
controllers<span class="token punctuation">:</span> <span class="token punctuation">[</span>AppController<span class="token punctuation">]</span><span class="token punctuation">,</span>
providers<span class="token punctuation">:</span> <span class="token punctuation">[</span>AppService<span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">AppModule</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
</code></pre><p>We updated our <code>app.module.ts</code> to use the config module. There are two things to notice here: when not in production, we read environment variables from the <code>.env</code> file. In production, notice that the <code>ignoreEnv</code> option will be <code>true</code>. This allows our app to read any environment variables we inject into the container when we run our application in the cloud.</p><p>We&rsquo;ll also need one endpoint. Let&rsquo;s now update the <code>app.controller.ts</code> file with the following:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Controller<span class="token punctuation">,</span> Get<span class="token punctuation">,</span> Post <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/common'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> AppService <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./app.service'</span><span class="token punctuation">;</span>

@<span class="token function">Controller</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">AppController</span> <span class="token punctuation">{</span>
<span class="token keyword">constructor</span><span class="token punctuation">(</span><span class="token keyword">private</span> readonly appService<span class="token punctuation">:</span> AppService<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

@<span class="token function">Get</span><span class="token punctuation">(</span><span class="token string">'/'</span><span class="token punctuation">)</span>
<span class="token function">getHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>appService<span class="token punctuation">.</span><span class="token function">getHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Also update your <code>app.service.ts</code> file with the following:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Injectable <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/common'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ConfigService <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/config'</span><span class="token punctuation">;</span>

@<span class="token function">Injectable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">AppService</span> <span class="token punctuation">{</span>
    <span class="token keyword">constructor</span><span class="token punctuation">(</span><span class="token keyword">private</span> readonly configService<span class="token punctuation">:</span> ConfigService<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token function">getHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>configService<span class="token punctuation">.</span>getOrThrow<span class="token operator">&lt;</span><span class="token keyword">string</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token string">'MESSAGE'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Our demo app has one route, <code>/</code>, which, when triggered, calls the <code>getHello</code> method. This method returns the value of the <code>MESSAGE</code> environment variable.</p><p>To see our running application, open your terminal and run the following command:</p><pre class=" language-shell"><code class="prism  language-shell">pnpm run start:dev
</code></pre><p>Our app currently listens on port 3000, as shown in the <code>main.ts</code> file below:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> NestFactory <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/core'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> AppModule <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./app.module'</span><span class="token punctuation">;</span>

<span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token keyword">await</span> NestFactory<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span>AppModule<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">await</span> app<span class="token punctuation">.</span><span class="token function">listen</span><span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>PORT <span class="token operator">?</span><span class="token operator">?</span> <span class="token number">3000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>Notice that our app listens on the special <code>process.env.PORT</code> value when provided. This will be important in production, since this value will be dynamically injected when the application is running within the container. For now, since we don&rsquo;t have it set locally, it defaults to port 3000.</p><p>Now visit <code>http://localhost:3000</code> to see the running application, as shown below:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/preview-of-local-nest-application.png?sfvrsn=632599f9_2" title="Preview of local Nest application" alt="Preview of local Nest application" /></p><h2 id="building-the-image">Building the Image</h2><p>We need to build the application&rsquo;s image before running it as a container. We already mentioned in the introductory section that the image can be built either locally or remotely.</p><p>When building locally, we can either use local buildpacks or, as in our case, leverage container runtimes like Docker or Podman.</p><p>Now, within the <code>my-nest-backend</code> folder, create a file called <code>Dockerfile</code> and update its contents as follows:</p><pre class=" language-js"><code class="prism  language-js">FROM node<span class="token punctuation">:</span><span class="token number">22</span><span class="token operator">-</span>alpine AS builder
WORKDIR <span class="token operator">/</span>app
RUN npm i <span class="token operator">-</span>g pnpm@<span class="token number">9</span>
COPY <span class="token keyword">package</span><span class="token punctuation">.</span>json pnpm<span class="token operator">-</span>lock<span class="token punctuation">.</span>yaml <span class="token punctuation">.</span><span class="token operator">/</span>
RUN pnpm install
COPY <span class="token punctuation">.</span> <span class="token punctuation">.</span>
RUN pnpm run build

FROM node<span class="token punctuation">:</span><span class="token number">22</span><span class="token operator">-</span>alpine AS runner
WORKDIR <span class="token operator">/</span>app
COPY <span class="token operator">--</span><span class="token keyword">from</span><span class="token operator">=</span>builder <span class="token operator">/</span>app<span class="token operator">/</span>node_modules <span class="token punctuation">.</span><span class="token operator">/</span>node_modules
COPY <span class="token operator">--</span><span class="token keyword">from</span><span class="token operator">=</span>builder <span class="token operator">/</span>app<span class="token operator">/</span>dist <span class="token punctuation">.</span><span class="token operator">/</span>dist
USER test
EXPOSE <span class="token number">3000</span>
CMD <span class="token punctuation">[</span><span class="token string">"node"</span><span class="token punctuation">,</span> <span class="token string">"dist/main.js"</span><span class="token punctuation">]</span>
</code></pre><p>Our Dockerfile is straightforward: it has two main stages. In the first stage, we install the pnpm package manager, use it to install all dependencies listed in <code>package.json</code>, and then build the app.</p><p>The second stage simply copies over the contents from the build step: the <code>node_modules</code> folder and the generated <code>dist</code> folder, from the first (<code>builder</code>) stage.</p><p>For security reasons, we also set the <code>USER</code> to <code>test</code> so that commands don&rsquo;t run as root. The <code>EXPOSE</code> instruction just documents in the image metadata that the app may listen on port 3000. Finally, the <code>CMD</code> instruction holds the command used to start the container from the image.</p><p>To build the image, open your terminal within the project directory and run the following command:</p><pre class=" language-shell"><code class="prism  language-shell">docker build . -f Dockerfile --platform linux/amd64 -t chrisnw/dummy-app:0002
</code></pre><p>The command above builds the image. The period (<code>.</code>) defines the build context, which in our case is the <code>my-nest-backend</code> folder. The <code>-f</code> flag specifies the file where the build script is located. This is optional if the file is named <code>Dockerfile</code>; we only added here for clarity.</p><p>Also notice that we specified the <code>--platform</code> flag and set it to <code>linux/amd64</code>. This is important to allow the generated image to run correctly, particularly when the image is built on an Apple Silicon machine.</p><p>We tag the image <code>chrisnw/dummy-app:0002</code>. This follows the standard format of <code>&lt;DOCKER_HUB_USERNAME&gt;/IMAGE_NAME:TAG</code>. If you don&rsquo;t have a Docker Hub username, feel free to create one.</p><p>To push the image to Docker Hub, run the following command:</p><pre class=" language-shell"><code class="prism  language-shell">docker push chrisnw/dummy-app:0002  
</code></pre><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/docker-image-pushed.png?sfvrsn=4fabe86a_2" title="Docker image pushed to the personal Docker Hub registry" alt="Docker image pushed to the personal Docker Hub registry" /></p><p>As seen above, the command executes successfully. The Docker image is pushed to the personal Docker Hub registry associated with the specified username.</p><h2 id="deploying-the-container-on-google-cloud-run">Deploying the Container on Google Cloud Run</h2><p>Internally, Google Cloud Run is based on Kubernetes, but with a simplified interface. Users are able to run any kind of workload, provided it&rsquo;s housed in a container. You can either provide a built image, like we did, or have Cloud Run build it for you, either by pointing it to your source code or by using their provided buildpacks to have the build done in the cloud.</p><p>To start, visit Google Cloud Platform and create a project. Note that we can use the <code>gcloud</code> CLI to execute all these steps in the terminal, but for simplicity, we&rsquo;ll be doing everything through the UI.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/creating-a-project-on-gcp.png?sfvrsn=a1c006d5_2" title="Creating a project on GCP" alt="Creating a project on GCP" /></p><p>Select the project as the default project, as shown below.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/selecting-a-project.png?sfvrsn=5d2a290b_2" title="Selecting a project" alt="Selecting a project" /></p><p>Next, we need to enable billing on our project to be able to use Cloud Run. Select <strong>Billing</strong> from the sidebar.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/locating-billing-option.png?sfvrsn=9e05f369_2" title="Locating the billing option" alt="Locating the billing option" /></p><p>Next, click on <strong>&ldquo;Link a billing account&rdquo;</strong> and select an account to link.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/enabling-billing.png?sfvrsn=eec54b13_2" title="Enabling billing on the project" alt="Enabling billing on the project" /></p><p>Now that billing is set up, we can go to the Cloud Run console. The quickest way to access it is by using the search bar.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/locating-cloud-run.png?sfvrsn=dd0168ce_2" title="Locating the Cloud Run application platform" alt="Locating the Cloud Run application platform" /></p><h2 id="creating-a-service">Creating a Service</h2><p>Now click on <strong>Cloud Run</strong>. Next, on the sidebar, select <strong>Services</strong> and click on <strong>Deploy container</strong>.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/creating-a-service.png?sfvrsn=3b83222b_2" title="Creating a service on Cloud run" alt="Creating a service on Cloud run" /></p><p>We chose the <strong>Service</strong> option because this is used for any HTTP-triggerable workload, like a web server in our case. Note that a service can be used to run one or more containers.</p><p>After clicking on <strong>Deploy container</strong> we&rsquo;re presented with a form to configure the service before deploying.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/configure-the-service.png?sfvrsn=2f79bde6_2" title="Form to configure the service" alt="Form to configure the service" /></p><p>We choose <strong>&ldquo;Deploy from a container image&rdquo;</strong>, then provide the URL to the image we just pushed to Docker Hub. We name our service <code>dummy-app</code>. Notice that we also get an automatically generated URL to visit our application. In our case, it&rsquo;s <code>https://dummy-app-847822676051.europe-west1.run.app/</code>.</p><h2 id="configuring-instances-and-billing">Configuring Instances and Billing</h2><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/request-based-billing.png?sfvrsn=751b99ae_2" title="Enabling request based billing for service" alt="Enabling request based billing for service" /></p><p>Services can be billed per request or per instance. Request-based billing, as the name implies, means you&rsquo;re charged per request to your server. This way, lower traffic means lower charges, and vice versa.</p><p>However, your server won&rsquo;t be able to run background tasks like CRON jobs or spawn workers to process tasks in a queue, since instances sleep when there&rsquo;s no traffic.</p><p>If your web server needs to do this, it&rsquo;s preferable to opt for instance-based billing and specify a minimum number of instances to run, so the server is reachable and running without any cold starts. For our small server, we&rsquo;re fine with the request-based setup.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/configure-resources-for-container.png?sfvrsn=bc2bdb8a_2" title="Configure resources for container" alt="Configure resources for container" /></p><p>Next, we need to configure the container settings. For memory and compute, we leave the defaults. We didn&rsquo;t set the container command field, since we already set it when we built the image&mdash;i.e., the <code>CMD ["node", "dist/main.js"]</code> we set earlier in our Dockerfile.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/adding-environment-variables.png?sfvrsn=37e60acc_2" title="Adding environment variables for container" alt="Adding environment variables for container" /></p><p>Next, we switch to the <strong>Variables and Secrets</strong> tab. We added one environment variable called <code>MESSAGE</code> and set its value to a dummy value we called <code>prod-message</code>. You can add multiple variables by clicking the <strong>Add variable</strong> button.</p><p>However, for sensitive credentials, like API keys or database connection strings, which shouldn&rsquo;t be exposed as plain text, you can click on <strong>&ldquo;Reference a secret&rdquo;</strong> to enable the Secret Manager API and add one or more secrets to reference here.</p><p>Finally, click on the <strong>Create</strong> button to deploy the service. If everything works fine, visit the URL now, and you should see the running application, as shown below:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/testing-the-production-url.png?sfvrsn=b54f812a_2" title="Testing the production URL" alt="Testing the production URL" /></p><h2 id="making-changes-and-redeploying-the-application">Making Changes and Redeploying the Application</h2><p>To redeploy our application, let&rsquo;s make a change to the code. Update your <code>app.service.ts</code> file.</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Injectable <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/common'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ConfigService <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/config'</span><span class="token punctuation">;</span>

@<span class="token function">Injectable</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">AppService</span> <span class="token punctuation">{</span>
 <span class="token keyword">constructor</span><span class="token punctuation">(</span><span class="token keyword">private</span> readonly configService<span class="token punctuation">:</span> ConfigService<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
 <span class="token function">getHello</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span> <span class="token punctuation">{</span>
   <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>configService<span class="token punctuation">.</span>getOrThrow<span class="token operator">&lt;</span><span class="token keyword">string</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token string">'MESSAGE'</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">''</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>We simply added an emoji to the returned string from our <code>getHello</code> method. Now we can proceed to build the image by running:</p><pre class=" language-shell"><code class="prism  language-shell">docker build . --platform linux/amd64 -t chrisnw/dummy-app:0003
</code></pre><p>And push the image by running:</p><pre class=" language-shell"><code class="prism  language-shell">docker push benguma/dummy-app:0003
</code></pre><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/redeploying-an-existing-service.png?sfvrsn=673390c2_2" title="Changing the image tag and redeploying an existing service" alt="Changing the image tag and redeploying an existing service" /></p><p>Now, on the <strong>Container</strong> tab, we update the field pointing to the new image. Click <strong>&ldquo;View diff and deploy&rdquo;</strong>, then click <strong>&ldquo;Deploy changes&rdquo;</strong>.</p><h2 id="automating-for-cicd">Automating for CI/CD</h2><p>Instead of manually building and publishing the image, we can make the build step part of our CI/CD pipeline using common options like GitHub Actions. Google Cloud Run also provides the necessary automation scripts we can plug in to speed up image building, pushing and deployment.</p><h2 id="conclusion">Conclusion</h2><p>Google Cloud Run makes it easy for developers to leverage the powerful features of Kubernetes, including its rich ecosystem of middleware and plugins, without dealing with the usual complexity. Hopefully, this demo can serve as a starting point for deploying similar workloads on Google Cloud Platform in your future projects.</p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">So the &lsquo;AI Differentiator&rsquo; Is Taste &hellip; But What IS Taste?</h4></div><div class="col-8"><p class="u-fs16 u-mb0"><a target="_blank" href="https://www.telerik.com/blogs/so-ai-differentiator-taste-but-what-taste">How do we define &ldquo;taste&rdquo; as developers?</a> And can we cultivate taste as a skill?</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17528831.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:213ce27b-6fba-4e4a-b71f-1fa47172dd7e</id>
    <title type="text">Blazor Basics: Introduction to Generic Type Support in Blazor</title>
    <summary type="text">Learn the benefits of using generic type arguments using the @typeparam directive to implement reusable and type-safe Razor components.</summary>
    <published>2026-11-17T17:28:00Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Claudio Bernasconi </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17528832/blazor-basics-introduction-generic-type-support-blazor"/>
    <content type="text"><![CDATA[<p><span class="featured">Learn the benefits of using generic type arguments using the @typeparam directive to implement reusable and type-safe Razor components.</span></p><p>Generic type support brings generic types to Razor components, letting us build scalable Blazor web applications.</p><p>In this article, we will learn how to use generic types in our Razor components and when we might want to consider using them.</p><p><strong>Hint:</strong> If you are new to generics in C#, please familiarize yourself first with generic types and methods in C# to be able to follow along.</p><p>You can <a target="_blank" href="https://github.com/claudiobernasconi/BlazorGenericTypeSupport">access the code on GitHub</a>.</p><h2 id="implementing-a-simple-generic-razor-component">Implementing a Simple Generic Razor Component</h2><p>The <code>@typeparam</code> attribute allows us to define a generic parameter for a Razor component.</p><p>Consider the following simple generic <code>NamedObjectRenderer</code> component:</p><pre class=" language-csharp"><code class="prism  language-csharp">@typeparam TType <span class="token keyword">where</span> TType <span class="token punctuation">:</span> INamedObject

<span class="token operator">&lt;</span>div<span class="token operator">&gt;</span>@Object<span class="token punctuation">.</span><span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">&gt;</span>

@code <span class="token punctuation">{</span>
    <span class="token punctuation">[</span>Parameter<span class="token punctuation">]</span>
    <span class="token keyword">public</span> required TType Object <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>This component defines a generic type using the <code>@typeparam</code> directive.</p><p>We can then use <code>TType</code> as the type for the parameter property called <code>Object</code>.</p><p>Since we use a <strong>type constraint</strong>, we can use the <code>GetName</code> method defined in the <code>INamedObject</code> interface:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">INamedObject</span>
<span class="token punctuation">{</span>
    <span class="token keyword">string</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>Now, let&rsquo;s use the component.</p><pre class=" language-csharp"><code class="prism  language-csharp">@code <span class="token punctuation">{</span>
    <span class="token keyword">private</span> Person person <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> Name <span class="token operator">=</span> <span class="token string">"Peter Parker"</span><span class="token punctuation">,</span> Age <span class="token operator">=</span> <span class="token number">22</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Person</span> <span class="token punctuation">:</span> INamedObject
    <span class="token punctuation">{</span>
        <span class="token keyword">public</span> required <span class="token keyword">string</span> Name <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
        <span class="token keyword">public</span> required <span class="token keyword">int</span> Age <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

        <span class="token keyword">public</span> <span class="token keyword">string</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> Name<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>First, we create a <code>Person</code> class that implements the <code>INamedObject</code> interface. We add two properties <code>Name</code> and <code>Age</code>, and provide the value of the <code>Name</code> property in the <code>GetName</code> method from the <code>INamedObject</code> interface.</p><p>The usage of the <code>NamedObjectRenderer</code> component is straightforward:</p><pre class=" language-html"><code class="prism  language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>NamedObjectRenderer</span> <span class="token attr-name">Object</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>person<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre><p>We provide an object of the <code>Person</code> class as the argument for the <code>Object</code> parameter of the <code>NamedObjectRenderer</code> component.</p><p><strong>Hint:</strong> Notice that we do not specifically provide the <code>Person</code> type as an argument for the <code>TType</code> parameter. That&rsquo;s possible because Blazor is able to infer the type of the provided object.</p><p>It&rsquo;s also possible to explicitly provide the type for the generic type argument. However, in most cases, type inference is good enough and makes using generic Razor components straightforward.</p><pre class=" language-html"><code class="prism  language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>NamedObjectRenderer</span> <span class="token attr-name">Object</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>person<span class="token punctuation">"</span></span> <span class="token attr-name">TType</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Person<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre><h2 id="implementing-a-higher-level-generic-razor-component">Implementing a Higher-Level Generic Razor Component</h2><p>The previous example demonstrated the foundation of how to implement generic Razor components.</p><p>I agree that the example doesn&rsquo;t feel revolutionary. There might be use cases here and there for it, but it does not change the general approach to how you will implement your Blazor web applications.</p><p>However, we can build on that foundation and implement a more advanced generic Razor component that has the potential to change how you structure and architect your Blazor web applications.</p><p><strong>Consider the following scenario:</strong> We want to render two columns on the screen. A name and a value column. We want to implement a single component to encapsulate the behavior and the look and feel of the component.</p><p><strong>But there is a twist!</strong> We want to be able to use that component with completely <strong>different</strong> data objects.</p><p>The following generic <code>DataTable</code> component is a great example:</p><pre class=" language-csharp"><code class="prism  language-csharp">@typeparam TItem

<span class="token operator">&lt;</span>table style<span class="token operator">=</span><span class="token string">"margin-top: 20px"</span><span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>thead<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>tr<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>th style<span class="token operator">=</span><span class="token string">"width: 120px"</span><span class="token operator">&gt;</span>Name<span class="token operator">&lt;</span><span class="token operator">/</span>th<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>th<span class="token operator">&gt;</span>Value<span class="token operator">&lt;</span><span class="token operator">/</span>th<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>tr<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>thead<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span>tbody<span class="token operator">&gt;</span>
        @<span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token keyword">var</span> item <span class="token keyword">in</span> Items<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token operator">&lt;</span>tr<span class="token operator">&gt;</span>
                <span class="token operator">&lt;</span>td<span class="token operator">&gt;</span>@<span class="token function">GetName</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token operator">&lt;</span><span class="token operator">/</span>td<span class="token operator">&gt;</span>
                <span class="token operator">&lt;</span>td<span class="token operator">&gt;</span>@<span class="token function">GetValue</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token operator">&lt;</span><span class="token operator">/</span>td<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span><span class="token operator">/</span>tr<span class="token operator">&gt;</span>
        <span class="token punctuation">}</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>tbody<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>table<span class="token operator">&gt;</span>

@code <span class="token punctuation">{</span>
    <span class="token punctuation">[</span>Parameter<span class="token punctuation">]</span>
    <span class="token keyword">public</span> IEnumerable<span class="token operator">&lt;</span>TItem<span class="token operator">&gt;</span> Items <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token punctuation">[</span>Parameter<span class="token punctuation">]</span>
    <span class="token keyword">public</span> required Func<span class="token operator">&lt;</span>TItem<span class="token punctuation">,</span> <span class="token keyword">string</span><span class="token operator">&gt;</span> GetName <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token punctuation">[</span>Parameter<span class="token punctuation">]</span>
    <span class="token keyword">public</span> required Func<span class="token operator">&lt;</span>TItem<span class="token punctuation">,</span> <span class="token keyword">string</span><span class="token operator">&gt;</span> GetValue <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Again, we define a generic type argument using the <code>@typeparam</code> directive at the top of the component.</p><p>In the code section, we use that type to implement three parameter properties. The <code>Items</code> property of type <code>IEnumerable&lt;TItem&gt;</code> contains a list of the provided items.</p><p>This list is looped through in the template section of the code, and for each item, the <code>GetName</code> and <code>GetValue</code> functions provided in the second and third component parameter are called.</p><p>Now, let&rsquo;s see how we can use that component in our applications and why this implementation is as powerful as I advertised it.</p><pre class=" language-csharp"><code class="prism  language-csharp">@page <span class="token string">"/"</span>

<span class="token operator">&lt;</span>DataTable Items<span class="token operator">=</span><span class="token string">"persons"</span>
           GetName<span class="token operator">=</span><span class="token string">"p =&gt; p.GetName()"</span>
           GetValue<span class="token operator">=</span><span class="token string">"p =&gt; p.Age.ToString()"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>

@code <span class="token punctuation">{</span>
    <span class="token keyword">private</span> Person<span class="token punctuation">[</span><span class="token punctuation">]</span> persons <span class="token operator">=</span> <span class="token punctuation">[</span>
        <span class="token keyword">new</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> Name <span class="token operator">=</span> <span class="token string">"Peter Parker"</span><span class="token punctuation">,</span> Age <span class="token operator">=</span> <span class="token number">22</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> 
        <span class="token keyword">new</span> <span class="token class-name">Person</span> <span class="token punctuation">{</span> Name <span class="token operator">=</span> <span class="token string">"Mary Jane"</span><span class="token punctuation">,</span> Age <span class="token operator">=</span> <span class="token number">20</span> <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Person</span> <span class="token punctuation">:</span> INamedObject
    <span class="token punctuation">{</span>
        <span class="token keyword">public</span> required <span class="token keyword">string</span> Name <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
        <span class="token keyword">public</span> required <span class="token keyword">int</span> Age <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

        <span class="token keyword">public</span> <span class="token keyword">string</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> Name<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Here, we have the same <code>Person</code> class we already used in the first chapter of this article. We create a list of <code>Person</code> objects and provide that list to the <code>Items</code> parameter of the <code>DataTable</code> component.</p><p>The magic happens in the definition of the <code>GetName</code> and <code>GetValue</code> parameter functions.</p><p>We use a lambda expression to define the behavior of the <code>GetName</code> and <code>GetValue</code> parameters.</p><p>For the <code>Person</code> class, we use its <code>GetName</code> method to render the person&rsquo;s name, and for the value column, we use the <code>Age</code> property and call its <code>ToString</code> method.</p><p><strong>By using a generic type argument, we can implement the behavior of the <code>DataTable</code> component outside the component definition.</strong></p><p>Let&rsquo;s look at a second example using a completely unrelated object:</p><pre class=" language-csharp"><code class="prism  language-csharp">@page <span class="token string">"/"</span>

<span class="token operator">&lt;</span>DataTable Items<span class="token operator">=</span><span class="token string">"animals"</span>
           GetName<span class="token operator">=</span><span class="token string">"p =&gt; p.Name"</span>
           GetValue<span class="token operator">=</span><span class="token string">"p =&gt; p.Type"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>

@code <span class="token punctuation">{</span>
    <span class="token keyword">private</span> Animal<span class="token punctuation">[</span><span class="token punctuation">]</span> animals <span class="token operator">=</span> <span class="token punctuation">[</span>
        <span class="token keyword">new</span> <span class="token class-name">Animal</span> <span class="token punctuation">{</span> Name <span class="token operator">=</span> <span class="token string">"Tom"</span><span class="token punctuation">,</span> Type <span class="token operator">=</span> <span class="token string">"Cat"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token keyword">new</span> <span class="token class-name">Animal</span> <span class="token punctuation">{</span> Name <span class="token operator">=</span> <span class="token string">"Cherry"</span><span class="token punctuation">,</span> Type <span class="token operator">=</span> <span class="token string">"Mouse"</span> <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Animal</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">public</span> required <span class="token keyword">string</span> Name <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
        <span class="token keyword">public</span> required <span class="token keyword">string</span> Type <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Here, we implement an <code>Animal</code> class with two properties <code>Name</code> and <code>Type</code>.</p><p>We want the animal&rsquo;s name (what the owner calls the pet) and its type (kind of animal).</p><p>We can reuse the same <code>DataTable</code> component and provide a list of animals to the <code>Items</code> property. Again, type inference works perfectly; we do not need to explicitly provide the <code>Animal</code> type.</p><p>And again, we implement the behavior from outside the <code>DataTable</code> component when we use it, rather than when we define it. We use the <code>Name</code> property for the name column value and the <code>Type</code> property for the value column.</p><p><strong>This example shows how to implement flexible, generic Razor components that let you share code across multiple uses of the same component and let each instance provide the behavior.</strong></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/generic-type-arguments-in-action.png?sfvrsn=172da4c0_2" title="Generic Type Arguments in Action" alt="A Blazor web application with two data tables rendered using the same DataTable component. Both tables look and feel the same with a Name column and a Value column." /></p><p><em>We can see that the look and feel of the first and the second list are exactly the same while we know that we provided two completely unrelated data types.</em></p><h2 id="the-advantages-of-generic-razor-components">The Advantages of Generic Razor Components</h2><p>We learned how to use the <code>@typeparam</code> directive to implement a generic type argument for Razor components.</p><p>We also implemented two examples that show how to build generic Razor components for your Blazor web applications.</p><p>Now, let&rsquo;s look at the advantages of using generic type arguments in Razor components more broadly:</p><ol><li>Generic type arguments make components <strong>more reusable</strong> and keep them type-safe. Instead of using object as the base type of a parameter or using <code>System.Reflection</code>, the compiler provides a type-safe environment.</li><li>Using the <code>Func&lt;TItem, ...&gt;</code> construct, we can <strong>inject/provide behavior from outside the component</strong>. It is possible to use different behavior in each component instance depending on the data provided.<br />The component in our second example does not need to know whether it renders a list of animals, persons, or buildings. But it is responsible for providing a consistent and user-friendly experience.</li><li>Thanks to <strong>type inference</strong>, we do not need to explicitly provide the generic type when using the component. Blazor can infer the type for us. This helps us keep the code concise and expressive.</li></ol><p><strong>In short:</strong> Generic type support lets us implement generic type arguments in Razor components, allowing us to reuse a type-safe component that provides a consistent look and feel and provides the behavior for each instance.</p><h2 id="conclusion">Conclusion</h2><p>Generic Razor components are a powerful tool for building reusable and type-safe Blazor applications. By using the <code>@typeparam</code> directive, we can create components that work with different data types.</p><p>Generic components can separate a component&rsquo;s presentation (rendering) from its data and behavior.</p><p>In the <code>DataTable</code> example component, we demonstrated how to use the same Razor component with two completely unrelated data classes.</p><p>Compared to implementing a Razor component for each data type and somehow finding a solution to share the template code, generic type arguments provide an elegant and concise solution.</p><p>If you want to learn more about Blazor development, watch my <a target="_blank" href="https://www.youtube.com/playlist?list=PLwISgxnkpZGL_LhTQCWwp-WCzupv7lcp0">free Blazor Crash Course</a> on YouTube. And stay tuned to the Telerik blog for more <a target="_blank" href="https://www.telerik.com/blogs/tag/blazor-basics">Blazor Basics</a>.</p><img src="https://feeds.telerik.com/link/10827/17528832.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:42b745bc-4a0c-4797-903b-e3a5003f3648</id>
    <title type="text">Is Convex Better Than Firebase?</title>
    <summary type="text">Convex comes with setup complexity, especially for non-React developers, but after that offers a great UX with capacity to scale. Firebase is easy to set up and manage, but gets more complex when scaling.</summary>
    <published>2026-11-13T16:07:24Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Jonathan Gamble </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17524028/is-convex-better-than-firebase"/>
    <content type="text"><![CDATA[<p><span class="featured">Convex comes with setup complexity, especially for non-React developers, but after that offers a great UX with capacity to scale. Firebase is easy to set up and manage, but gets more complex when scaling.</span></p><p>I have created a todo app many times. What seems like something very simple can get complicated really quickly when you have to learn a new stack, build your own backend or think differently than you are used to.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/convex-todo.png?sfvrsn=1f9337e0_2" alt="Convex Tasks todo list" /></p><h2 id="tldr">TL;DR</h2><p>Convex is extremely difficult to set up, especially for non-React users. The Authentication package <em>ONLY</em> works for React, and had to be written from scratch, which is a big negative. It is missing basic features and is overly complicated.</p><p>However, once Convex is properly set up for development and production, the actual developer experience is amazing and has a lot of potential for scaling a real noSQL app with fewer hurdles.</p><p>Firebase is easier to set up, manage and deploy, but the learning curve grows when you need to manage security and scaling. Convex is the opposite, due to the TypeScript first ecosystem.</p><h3 id="prerequisite-✅">Prerequisite ✅</h3><p>I&rsquo;m going to assume you have basic knowledge of <a target="_blank" href="https://nuxt.com/">Nuxt 4</a>, <a target="_blank" href="https://tailwindcss.com/docs/installation/framework-guides/nuxt">Tailwind</a> and <a target="_blank" href="https://firebase.google.com/">Firebase</a>. I&rsquo;m going to focus on Convex.</p><h2 id="what-is-convex">What Is Convex?</h2><p>Convex is a noSQL database platform that allows you to consume real-time data on the client in any form that you like. It does NOT allow true relational data, but you can query several documents at once, very close to the data itself, emulating a join. </p><p>Everything is written in TypeScript, so you don&rsquo;t have to worry about complex security rules. Instead of trigger functions, you directly write your complexities inside the mutation itself, which lives on the Convex server. Authentication is sparse, but if you use Google or GitHub with React, you should have no problems.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/convex-database.png?sfvrsn=ee3baabb_2" alt="Convex database" /></p><h2 id="what-is-firebase">What Is Firebase?</h2><p>Firebase is a cloud platform with a noSQL database, authentication, security rules, cloud functions, etc. It is arguably the easiest database to learn, especially if you don&rsquo;t need complex schemas or scaling. It has incredible querying capabilities for noSQL, second only to <a target="_blank" href="https://www.mongodb.com/">MongoDB.</a> </p><p>Once you need tightened security, more complex data modeling or testing, the learning curve increases dramatically. It works out of the box in all frameworks.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/firebasedatabase.png?sfvrsn=8b95c7ef_2" alt="Firebase database" /></p><h2 id="convex-app-setup">Convex App Setup</h2><h3 id="create-a-new-convex-project">Create a New Convex Project</h3><p>Login to <a target="_blank" href="https://www.convex.dev/">Convex</a> and create a new project.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/convex-create-project.png?sfvrsn=4eb751ce_2" alt="Convex create new project" /></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/convex-new-deployment.png?sfvrsn=3e62002e_2" alt="Convex create new deployment" /></p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/nuxt-convex.png?sfvrsn=28b63b79_2" alt="Nuxt-Convex in project list" /></p><p> Notice you have a <code>production</code> and <code>development</code> database by default.</p><p> You also don&rsquo;t have to worry about your free project auto-pausing, hence I have a demo below that can be free forever.</p><h3 id="create-a-nuxt-app">Create a Nuxt App</h3><pre class=" language-tsx"><code class="prism  language-tsx">npm create nuxt@latest
</code></pre><h3 id="install-tailwind">Install Tailwind</h3><p>Don&rsquo;t use the package. Follow the official <a target="_blank" href="https://tailwindcss.com/docs/installation/framework-guides/nuxt">Tailwind Guide</a>.</p><h3 id="install-convex">Install Convex</h3><p>I&rsquo;m modifying the official <a target="_blank" href="https://docs.convex.dev/quickstart/nuxt">Nuxt Convex Quickstart</a>.</p><ol><li>Install the Convex Library once in your new project.</li></ol><pre class=" language-bash"><code class="prism  language-bash"><span class="token function">npm</span> <span class="token function">install</span> convex <span class="token operator">&amp;&amp;</span> npx nuxi module add convex-nuxt
</code></pre><ol start="2"><li>Add the Convex URL.</li></ol><pre class=" language-tsx"><code class="prism  language-tsx">// nuxt.config.ts

import tailwindcss from "@tailwindcss/vite";

export default defineNuxtConfig({
  compatibilityDate: "2025-07-15",
  devtools: { enabled: true },
  css: ['~/assets/css/main.css'],
  vite: {
    plugins: [
      tailwindcss(),
    ],
  },
  modules: ["convex-nuxt"],
  convex: {
    url: process.env.CONVEX_URL,
  },
});
</code></pre><ol start="3"><li>Set up a Convex dev deployment.</li></ol><pre class=" language-bash"><code class="prism  language-bash">npx convex dev
</code></pre><p> This will be run in the background at all times to keep your app going.</p><p>You should see on <code>.env.local</code> variable:</p><pre class=" language-bash"><code class="prism  language-bash">NUXT_PUBLIC_CONVEX_URL<span class="token operator">=</span>https://your-deployment.convex.cloud
</code></pre><ol start="4"><li>Set up Convex Auth.</li></ol><pre class=" language-bash"><code class="prism  language-bash">npx @convex-dev/auth
</code></pre><p> You may have to manually install <code>@convex-dev/auth</code> or <code>@auth/core</code>.</p><pre class=" language-tsx"><code class="prism  language-tsx">// convex/auth.config.ts

export default {
  providers: [
    {
      domain: process.env.CONVEX_SITE_URL,
      applicationID: "convex",
    },
  ],
};
</code></pre><p>4b. (Optional)</p><p>I had to create this file. It could also be <code>http.js</code> if not there. Again, the auth setup is not intuitive and I ran into several issues.</p><pre class=" language-tsx"><code class="prism  language-tsx">// convex/http.ts

import { httpRouter } from "convex/server";
import { auth } from "./auth";

const http = httpRouter();

auth.addHttpRoutes(http);

export default http;
</code></pre><ol start="5"><li>Set up GitHub</li></ol><p>Log in to your GitHub. Then go to <em>Settings</em> &rarr; <em>Developer Settings</em> &rarr; <em>OAuth Apps</em> and create a new app.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/github-auth.png?sfvrsn=dbfb18ae_2" alt="GitHub app creation with fields for app name, homepage URL, authorization callback URL, etc." /></p><p>Copy your <code>secret key</code> and <code>client key</code>. Remember to save your secret key, as you can never get it back!</p><pre class=" language-bash"><code class="prism  language-bash">npx convex <span class="token function">env</span> <span class="token keyword">set</span> AUTH_GITHUB_ID your-github-client-id
npx convex <span class="token function">env</span> <span class="token keyword">set</span> AUTH_GITHUB_SECRET your-github-client-secret
</code></pre><p> Your environment variables exist on the convex server, so these are NOT your app&rsquo;s env variables!</p><pre class=" language-tsx"><code class="prism  language-tsx">// convex/auth.ts

import GitHub from "@auth/core/providers/github";
import { convexAuth } from "@convex-dev/auth/server";

export const {
  auth,
  signIn,
  signOut,
  store,
  isAuthenticated,
} = convexAuth({
  providers: [
    GitHub({
      clientId: process.env.AUTH_GITHUB_ID,
      clientSecret: process.env.AUTH_GITHUB_SECRET,
    }),
  ],
});
</code></pre><ol start="6"><li>Define your tasks schema.</li></ol><pre class=" language-tsx"><code class="prism  language-tsx">// convex/schema.ts

import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
import { authTables } from "@convex-dev/auth/server";

export default defineSchema({
  ...authTables,
  tasks: defineTable({
    userId: v.id("users"),
    text: v.string(),
    isCompleted: v.boolean(),
  }).index("by_user", ["userId"]),
});
</code></pre><ol start="7"><li>Expose your database queries.</li></ol><pre class=" language-tsx"><code class="prism  language-tsx">// convex/tasks.ts

import { v } from "convex/values";
import { getAuthUserId } from "@convex-dev/auth/server";
import { mutation, query } from "./_generated/server";

export const get = query({
  args: {},
  handler: async (ctx) =&gt; {
    const userId = await getAuthUserId(ctx);

    if (!userId) {
      return [];
    }

    return await ctx.db
      .query("tasks")
      .withIndex("by_user", (q) =&gt; q.eq("userId", userId))
      .order("desc")
      .collect();
  },
});

export const create = mutation({
  args: {
    text: v.string(),
  },
  handler: async (ctx, args) =&gt; {
    const userId = await getAuthUserId(ctx);

    if (!userId) {
      return null;
    }

    return await ctx.db.insert("tasks", {
      userId,
      text: args.text,
      isCompleted: false,
    });
  },
});

export const toggleCompleted = mutation({
  args: {
    id: v.id("tasks"),
    isCompleted: v.boolean(),
  },
  handler: async (ctx, args) =&gt; {
    const userId = await getAuthUserId(ctx);

    if (!userId) {
      return;
    }

    const task = await ctx.db.get(args.id);

    if (!task || task.userId !== userId) {
      return;
    }

    await ctx.db.patch(args.id, {
      isCompleted: args.isCompleted,
    });
  },
});

export const remove = mutation({
  args: {
    id: v.id("tasks"),
  },
  handler: async (ctx, args) =&gt; {
    const userId = await getAuthUserId(ctx);

    if (!userId) {
      return;
    }

    const task = await ctx.db.get(args.id);

    if (!task || task.userId !== userId) {
      return;
    }

    await ctx.db.delete(args.id);
  },
});
</code></pre><ul><li>The query function returns all tasks by a certain user. We use our <code>by_user</code> index to filter, and order by <code>_creationTime</code> (internal variable) descending.</li><li>We create a new task by the user.</li><li>We update the completed task by a user.</li><li>We remove a task by a user.</li></ul><p> All of these are secure, close to the database and extremely fast. The fact that we have to run multiple database calls is negligible in this case!</p><h2 id="creating-our-app">Creating Our App</h2><p>Even though the <code>convex</code> folder is created on our server, it does not live there. The rest of the code actually lives in our app.</p><h3 id="composables">Composables</h3><p>If you follow any of my articles, you know that I firmly believe your core code should ALWAYS be separate from the component, in a composable, not in the component.</p><pre class=" language-tsx"><code class="prism  language-tsx">// composables/useTask.ts

import { api } from "~~/convex/_generated/api";
import type { Doc, Id } from "~~/convex/_generated/dataModel";

export type TaskItem = Doc&lt;"tasks"&gt;;

const queryArgs = {};

export function useTasks() {
  const { data, isPending, error } = useConvexQuery(api.tasks.get);

  const tasks = computed&lt;TaskItem[]&gt;(() =&gt; data.value ?? []);

  const {
    mutate: createTask,
    isPending: isCreating,
    error: createError,
  } = useConvexMutation(api.tasks.create, {
    optimisticUpdate: (localStore, args) =&gt; {
      const currentTasks = localStore.getQuery(api.tasks.get, queryArgs);

      if (!currentTasks) return;

      const now = Date.now();
      const optimisticTask: Doc&lt;"tasks"&gt; = {
        _id: `pending-${crypto.randomUUID()}` as Id&lt;"tasks"&gt;,
        _creationTime: now,
        userId:
          currentTasks[0]?.userId ??
          (`pending-${crypto.randomUUID()}` as Id&lt;"users"&gt;),
        text: args.text,
        isCompleted: false,
      };

      localStore.setQuery(api.tasks.get, queryArgs, [
        optimisticTask,
        ...currentTasks,
      ]);
    },
  });

  const { mutate: updateTask } = useConvexMutation(
    api.tasks.toggleCompleted,
    {
      optimisticUpdate: (localStore, args) =&gt; {
        const currentTasks = localStore.getQuery(api.tasks.get, queryArgs);

        if (!currentTasks) return;

        localStore.setQuery(
          api.tasks.get,
          queryArgs,
          currentTasks.map((task) =&gt;
            task._id === args.id
              ? { ...task, isCompleted: args.isCompleted }
              : task,
          ),
        );
      },
    },
  );

  const { mutate: deleteTask } = useConvexMutation(api.tasks.remove, {
    optimisticUpdate: (localStore, args) =&gt; {
      const currentTasks = localStore.getQuery(api.tasks.get, queryArgs);

      if (!currentTasks) return;

      localStore.setQuery(
        api.tasks.get,
        queryArgs,
        currentTasks.filter((task) =&gt; task._id !== args.id),
      );
    },
  });

  async function addTask(text: string) {
    return await createTask({ text });
  }

  function toggleTask(task: TaskItem) {
    if (task._id.startsWith("pending-")) return;

    return updateTask({
      id: task._id,
      isCompleted: !task.isCompleted,
    });
  }

  function removeTask(task: TaskItem) {
    if (task._id.startsWith("pending-")) return;

    return deleteTask({ id: task._id });
  }

  return {
    tasks,
    isPending,
    error,
    isCreating,
    createError,
    addTask,
    toggleTask,
    removeTask,
  };
}
</code></pre><ul><li><code>useConvexQuery</code> is simple, has a pending and error state and can be passed directly to our app.</li><li><code>useConvexMutation</code> is more complicated. We want our apps to be immediate, so we must add the optimistic update strategy like Firebase has.</li><li>There is a <code>optimisticUpdate</code> option that gives you access to <code>localStore.getQuery</code> and <code>localStore.setQuery</code>. We can set our items optimistically, and Convex will automatically roll it back if there is an issue.</li></ul><h3 id="app.vue">app.vue</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script setup lang="ts"&gt;
const { error: authError, isAuthenticated, isLoading, signIn, signOut } = useConvexAuth();
&lt;/script&gt;

&lt;template&gt;
  &lt;div class="min-h-screen bg-[radial-gradient(circle_at_top_left,#d8f3dc,transparent_32rem),linear-gradient(135deg,#fffaf0_0%,#f8fafc_48%,#e0f2fe_100%)] px-4 py-10 text-slate-950 sm:px-6 lg:px-8"&gt;
    &lt;main class="mx-auto flex w-full max-w-2xl flex-col gap-6"&gt;
      &lt;header class="space-y-3"&gt;
        &lt;p class="text-sm font-semibold uppercase tracking-[0.18em] text-teal-700"&gt;Convex tasks&lt;/p&gt;
        &lt;div class="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between"&gt;
          &lt;div&gt;
            &lt;h1 class="font-serif text-5xl font-bold tracking-normal text-slate-950 sm:text-6xl"&gt;Tasks&lt;/h1&gt;
            &lt;p class="mt-2 max-w-xl text-base leading-7 text-slate-600"&gt;Add what needs doing, then check it off when it is done.&lt;/p&gt;
          &lt;/div&gt;
          &lt;button
            v-if="isAuthenticated"
            class="flex min-h-11 min-w-24 items-center justify-center rounded-md border border-slate-200 bg-white px-4 text-sm font-semibold text-slate-700 shadow-sm transition hover:-translate-y-0.5 hover:border-rose-200 hover:bg-rose-50 hover:text-rose-700 focus:outline-none focus:ring-4 focus:ring-rose-100 disabled:translate-y-0 disabled:cursor-not-allowed disabled:text-slate-400"
            type="button"
            :disabled="isLoading"
            :aria-label="isLoading ? 'Signing out' : undefined"
            @click="signOut()"
          &gt;
            &lt;LoadingSpinner v-if="isLoading" class="size-5" /&gt;
            &lt;span v-else&gt;Sign out&lt;/span&gt;
          &lt;/button&gt;
        &lt;/div&gt;
      &lt;/header&gt;

      &lt;section
        v-if="isLoading &amp;&amp; !isAuthenticated"
        class="flex min-h-40 items-center justify-center rounded-lg border border-white/70 bg-white/85 p-8 shadow-xl shadow-slate-200/70 ring-1 ring-slate-900/5 backdrop-blur sm:p-10"
        role="status"
        aria-label="Loading your tasks"
      &gt;
        &lt;LoadingSpinner class="size-8" /&gt;
      &lt;/section&gt;

      &lt;LoginWithGithub
        v-else-if="!isAuthenticated"
        :error="authError"
        @sign-in="signIn('github')"
      /&gt;

      &lt;template v-else&gt;
        &lt;div class="rounded-lg border border-white/70 bg-white/85 p-5 shadow-xl shadow-slate-200/70 ring-1 ring-slate-900/5 backdrop-blur sm:p-6"&gt;
          &lt;AddTask /&gt;
        &lt;/div&gt;

        &lt;TaskList /&gt;
      &lt;/template&gt;
    &lt;/main&gt;
  &lt;/div&gt;
&lt;/template&gt;
</code></pre><p>We show a loading spinner or a Sign In button.</p><h3 id="addtask.vue">AddTask.vue</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script setup lang="ts"&gt;
import { computed, ref } from "vue";

const text = ref("");
const trimmedText = computed(() =&gt; text.value.trim());
const { addTask: createTask, isCreating, createError } = useTasks();

async function addTask() {
  if (!trimmedText.value || isCreating.value) {
    return;
  }

  await createTask(trimmedText.value);
  text.value = "";
}
&lt;/script&gt;

&lt;template&gt;
  &lt;form class="space-y-4" @submit.prevent="addTask"&gt;
    &lt;div class="flex flex-col gap-1"&gt;
      &lt;label class="text-sm font-semibold text-slate-800" for="task-text"&gt;New task&lt;/label&gt;
      &lt;p class="text-sm text-slate-500"&gt;Capture it before it escapes the moment.&lt;/p&gt;
    &lt;/div&gt;

    &lt;div class="flex flex-col gap-3 sm:flex-row"&gt;
      &lt;input
        id="task-text"
        v-model="text"
        class="min-h-12 flex-1 rounded-md border border-slate-200 bg-white px-4 text-base text-slate-950 shadow-sm outline-none transition placeholder:text-slate-400 hover:border-slate-300 focus:border-teal-500 focus:ring-4 focus:ring-teal-100 disabled:cursor-not-allowed disabled:bg-slate-50 disabled:text-slate-400"
        type="text"
        placeholder="Add a task"
        :disabled="isCreating"
      &gt;
      &lt;button
        class="min-h-12 rounded-md bg-slate-950 px-5 text-sm font-semibold text-white shadow-lg shadow-slate-900/15 transition hover:-translate-y-0.5 hover:bg-teal-700 focus:outline-none focus:ring-4 focus:ring-teal-200 disabled:translate-y-0 disabled:cursor-not-allowed disabled:bg-slate-300 disabled:shadow-none sm:w-36"
        type="submit"
        :disabled="!trimmedText || isCreating"
      &gt;
        {{ isCreating ? "Adding..." : "Add task" }}
      &lt;/button&gt;
    &lt;/div&gt;

    &lt;p v-if="createError" class="rounded-md bg-rose-50 px-3 py-2 text-sm font-medium text-rose-700"&gt;
      Unable to add task.
    &lt;/p&gt;
  &lt;/form&gt;
&lt;/template&gt;
</code></pre><p>Again, with our composable all we really need to do is show the input button and error.</p><h3 id="tasklist.vue">TaskList.vue</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script setup lang="ts"&gt;
const { tasks, isPending, error, toggleTask, removeTask } = useTasks();
&lt;/script&gt;

&lt;template&gt;
    &lt;section class="overflow-hidden rounded-lg border border-slate-200/80 bg-white/90 shadow-xl shadow-slate-200/60 ring-1 ring-slate-900/5 backdrop-blur"&gt;
        &lt;div class="border-b border-slate-100 bg-slate-50/80 p-5 sm:p-6"&gt;
            &lt;div class="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between"&gt;
                &lt;div&gt;
                    &lt;p class="text-xs font-semibold uppercase tracking-[0.18em] text-teal-700"&gt;Today&lt;/p&gt;
                    &lt;h2 class="mt-1 text-2xl font-bold text-slate-950"&gt;Your list&lt;/h2&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class="p-5 sm:p-6"&gt;
            &lt;div
                v-if="isPending"
                class="flex items-center justify-center rounded-md border border-dashed border-slate-300 bg-slate-50 px-4 py-8"
                role="status"
                aria-label="Loading tasks"
            &gt;
                &lt;LoadingSpinner /&gt;
            &lt;/div&gt;
            &lt;p v-else-if="error" class="rounded-md bg-rose-50 px-4 py-3 text-sm font-medium text-rose-700"&gt;
                Unable to load tasks.
            &lt;/p&gt;
            &lt;ul v-else-if="tasks.length" class="space-y-3"&gt;
                &lt;li
                    v-for="task in tasks"
                    :key="task._id"
                    class="group rounded-md border border-slate-200 bg-white px-4 py-3 shadow-sm transition duration-200 hover:-translate-y-0.5 hover:border-teal-200 hover:shadow-md"
                &gt;
                    &lt;div class="flex items-center gap-3"&gt;
                    &lt;label class="flex min-w-0 flex-1 cursor-pointer items-center gap-3"&gt;
                        &lt;input
                            class="size-5 rounded border-slate-300 accent-teal-600 transition group-hover:scale-105"
                            type="checkbox"
                            :checked="task.isCompleted"
                            @change="toggleTask(task)"
                        &gt;
                        &lt;span
                            class="min-w-0 flex-1 wrap-break-word text-base font-medium text-slate-800 transition"
                            :class="task.isCompleted ? 'text-slate-400 line-through decoration-2' : ''"
                        &gt;
                            {{ task.text }}
                        &lt;/span&gt;
                    &lt;/label&gt;
                    &lt;button
                        class="flex size-9 shrink-0 items-center justify-center rounded-md text-slate-400 transition hover:bg-rose-50 hover:text-rose-700 focus:outline-none focus:ring-4 focus:ring-rose-100"
                        type="button"
                        :aria-label="`Delete ${task.text}`"
                        title="Delete task"
                        @click="removeTask(task)"
                    &gt;
                        &lt;span
                            class="size-4 bg-current"
                            aria-hidden="true"
                            style="mask: url('/delete.svg') center / contain no-repeat; -webkit-mask: url('/delete.svg') center / contain no-repeat;"
                        /&gt;
                    &lt;/button&gt;
                    &lt;/div&gt;
                &lt;/li&gt;
            &lt;/ul&gt;
            &lt;div v-else class="rounded-md border border-dashed border-slate-300 bg-slate-50 px-4 py-10 text-center"&gt;
                &lt;p class="text-sm font-semibold text-slate-700"&gt;No tasks yet&lt;/p&gt;
                &lt;p class="mt-1 text-sm text-slate-500"&gt;Add the first one above.&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/section&gt;
&lt;/template&gt;
</code></pre><p>We can easily show our task, handle removing them with a button and toggle completed state.</p><h3 id="loginwithgithub.vue">LoginWithGithub.vue</h3><pre class=" language-tsx"><code class="prism  language-tsx">&lt;script setup lang="ts"&gt;
defineProps&lt;{
  error: string | null;
}&gt;();

defineEmits&lt;{
  signIn: [];
}&gt;();
&lt;/script&gt;

&lt;template&gt;
  &lt;section class="rounded-lg border border-white/70 bg-white/85 p-8 text-center shadow-xl shadow-slate-200/70 ring-1 ring-slate-900/5 backdrop-blur sm:p-10"&gt;
    &lt;h2 class="text-2xl font-bold text-slate-950"&gt;Sign in to see your tasks&lt;/h2&gt;
    &lt;p class="mx-auto mt-2 max-w-md text-sm leading-6 text-slate-500"&gt;Use GitHub to open your private task list.&lt;/p&gt;
    &lt;button
      class="mx-auto mt-6 flex min-h-12 items-center justify-center gap-3 rounded-md bg-slate-950 px-5 text-sm font-semibold text-white shadow-lg shadow-slate-900/15 transition hover:-translate-y-0.5 hover:bg-teal-700 focus:outline-none focus:ring-4 focus:ring-teal-200"
      type="button"
      @click="$emit('signIn')"
    &gt;
      &lt;GithubIcon /&gt;
      Login with GitHub
    &lt;/button&gt;
    &lt;p v-if="error" class="mt-4 rounded-md bg-rose-50 px-3 py-2 text-sm font-medium text-rose-700"&gt;
      {{ error }}
    &lt;/p&gt;
  &lt;/section&gt;
&lt;/template&gt;
</code></pre><p>Of course we have to show our GitHub login.</p><pre class=" language-tsx"><code class="prism  language-tsx">// GithubIcon.vue

&lt;template&gt;
  &lt;svg
    class="size-5"
    viewBox="0 0 24 24"
    fill="currentColor"
    aria-hidden="true"
  &gt;
    &lt;path d="M12 2C6.48 2 2 6.58 2 12.23c0 4.52 2.87 8.35 6.84 9.71.5.09.68-.22.68-.49 0-.24-.01-1.04-.01-1.88-2.78.62-3.37-1.22-3.37-1.22-.45-1.18-1.11-1.49-1.11-1.49-.91-.64.07-.63.07-.63 1 .07 1.53 1.05 1.53 1.05.89 1.56 2.34 1.11 2.91.85.09-.66.35-1.11.63-1.36-2.22-.26-4.55-1.14-4.55-5.06 0-1.12.39-2.03 1.03-2.74-.1-.26-.45-1.3.1-2.71 0 0 .84-.27 2.75 1.05A9.29 9.29 0 0 1 12 6.97c.85 0 1.71.12 2.51.35 1.9-1.32 2.74-1.05 2.74-1.05.55 1.41.2 2.45.1 2.71.64.71 1.03 1.62 1.03 2.74 0 3.93-2.34 4.8-4.57 5.05.36.32.68.94.68 1.9 0 1.37-.01 2.47-.01 2.8 0 .27.18.59.69.49A10.14 10.14 0 0 0 22 12.23C22 6.58 17.52 2 12 2Z" /&gt;
  &lt;/svg&gt;
&lt;/template&gt;
</code></pre><p>And loading spinner.</p><pre class=" language-tsx"><code class="prism  language-tsx">// LoadingSpinner.vue

&lt;template&gt;
  &lt;svg
    class="size-6 animate-spin text-teal-600"
    viewBox="0 0 24 24"
    fill="none"
    aria-hidden="true"
  &gt;
    &lt;circle
      class="opacity-25"
      cx="12"
      cy="12"
      r="10"
      stroke="currentColor"
      stroke-width="4"
    /&gt;
    &lt;path
      class="opacity-75"
      fill="currentColor"
      d="M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4Z"
    /&gt;
  &lt;/svg&gt;
&lt;/template&gt;
</code></pre><h3 id="⚠️-no-convex-composable">⚠️ No Convex Composable</h3><p>Convex is meant for React. They don&rsquo;t have the ability to log in or log out natively outside of React!!! If you dislike React as much as I do, you have to string together working auth client functions from their React codebase. This works, but is just generated slop code. Hopefully they fix this for Nuxt and SvelteKit at the very least.</p><pre class=" language-tsx"><code class="prism  language-tsx">// composables/useConvexAuth.ts

import { ConvexHttpClient } from "convex/browser";
import type { FunctionReference } from "convex/server";
import type { Value } from "convex/values";

type Tokens = {
  token: string;
  refreshToken: string;
};

type SignInResult = {
  redirect?: string;
  verifier?: string;
  tokens?: Tokens | null;
};

const signInAction =
  "auth:signIn" as unknown as FunctionReference&lt;"action"&gt;;

const signOutAction =
  "auth:signOut" as unknown as FunctionReference&lt;"action"&gt;;

export function useConvexAuth() {
  const client = useConvexClient();
  const config = useRuntimeConfig();

  const convexUrl = config.public.convex.url as string;
  const storageSuffix = convexUrl.replace(/[^a-zA-Z0-9]/g, "");

  const verifierKey = `__convexAuthOAuthVerifier_${storageSuffix}`;
  const jwtKey = `__convexAuthJWT_${storageSuffix}`;
  const refreshTokenKey = `__convexAuthRefreshToken_${storageSuffix}`;

  const isAuthenticated = useState(
    "convex-auth-authenticated",
    () =&gt; false,
  );

  const isLoading = useState(
    "convex-auth-loading",
    () =&gt; true,
  );

  const error = useState&lt;string | null&gt;(
    "convex-auth-error",
    () =&gt; null,
  );

  const initialized = useState(
    "convex-auth-initialized",
    () =&gt; false,
  );

  function clearTokens() {
    localStorage.removeItem(jwtKey);
    localStorage.removeItem(refreshTokenKey);
    isAuthenticated.value = false;
  }

  function saveTokens(tokens: Tokens) {
    localStorage.setItem(jwtKey, tokens.token);
    localStorage.setItem(refreshTokenKey, tokens.refreshToken);
  }

  async function exchangeAuthData(
    args:
      | { code: string; verifier?: string }
      | { refreshToken: string },
  ) {
    // Use a separate unauthenticated client so refreshing a token
    // does not recursively trigger the authenticated client.
    const httpClient = new ConvexHttpClient(convexUrl);

    const result = await httpClient.action(
      signInAction,
      "code" in args
        ? {
          params: { code: args.code },
          verifier: args.verifier,
        }
        : args,
    ) as { tokens: Tokens | null };

    if (!result.tokens) {
      clearTokens();
      return null;
    }

    saveTokens(result.tokens);

    return result.tokens.token;
  }

  async function fetchAccessToken({
    forceRefreshToken,
  }: {
    forceRefreshToken: boolean;
  }) {
    if (!forceRefreshToken) {
      return localStorage.getItem(jwtKey);
    }

    const refreshToken = localStorage.getItem(refreshTokenKey);

    if (!refreshToken) {
      clearTokens();
      return null;
    }

    return await exchangeAuthData({ refreshToken });
  }

  function configureClientAuth() {
    client.setAuth(fetchAccessToken, (authenticated) =&gt; {
      isAuthenticated.value = authenticated;

      if (!authenticated) {
        clearTokens();
      }
    });
  }

  async function initialize() {
    if (!import.meta.client || initialized.value) {
      return;
    }

    initialized.value = true;
    isLoading.value = true;

    try {
      const url = new URL(window.location.href);
      const code = url.searchParams.get("code");

      if (code) {
        const verifier =
          localStorage.getItem(verifierKey) ?? undefined;

        localStorage.removeItem(verifierKey);

        url.searchParams.delete("code");

        window.history.replaceState(
          {},
          "",
          `${url.pathname}${url.search}${url.hash}`,
        );

        await exchangeAuthData({ code, verifier });
      }

      if (localStorage.getItem(jwtKey)) {
        configureClientAuth();
      } else {
        isAuthenticated.value = false;
      }
    } catch (cause) {
      clearTokens();

      error.value =
        cause instanceof Error
          ? cause.message
          : "Authentication failed.";
    } finally {
      isLoading.value = false;
    }
  }

  async function signIn(provider = "github") {
    error.value = null;
    isLoading.value = true;

    try {
      const result = await client.action(signInAction, {
        provider,
        params: {
          redirectTo: window.location.pathname,
        },
      } satisfies Record&lt;string, Value&gt;) as SignInResult;

      if (result.redirect) {
        if (result.verifier) {
          localStorage.setItem(verifierKey, result.verifier);
        }

        window.location.assign(result.redirect);
        return;
      }

      if (result.tokens) {
        saveTokens(result.tokens);
        configureClientAuth();
      }
    } catch (cause) {
      error.value =
        cause instanceof Error
          ? cause.message
          : "Unable to sign in.";

      isLoading.value = false;
    }
  }

  async function signOut() {
    error.value = null;
    isLoading.value = true;

    try {
      await client.action(signOutAction, {});
    } finally {
      clearTokens();
      client.setAuth(async () =&gt; null);
      isLoading.value = false;
    }
  }

  onMounted(initialize);

  return {
    error: readonly(error),
    isAuthenticated: readonly(isAuthenticated),
    isLoading: readonly(isLoading),
    signIn,
    signOut,
  };
}
</code></pre><p> These functions just handle signing in and out, loading and authenticated states.</p><p> What bothers me the most about this is that this code doesn&rsquo;t have to be React-specific. It just sets some storage states, etc. It doesn&rsquo;t do anything special, as that is already handled in the core code. This is client-only, not even SSR. What&rsquo;s worse is that this could easily have been built framework-agnostic anyway. Instead, we have another React-only database. ☹️ People hate JSX, it is a thing; they just deal with it.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/convex-todo-action.gif?sfvrsn=c111661f_2" alt="Convex todo app function tests" /></p><h2 id="verdict">Verdict</h2><h3 id="what-convex-says">What Convex Says</h3><p>Let&rsquo;s start with <a target="_blank" href="https://www.convex.dev/compare/firebase">Convex&rsquo;s comparison</a>:</p><table><style>table,
 th,
    td {
      border: 1px;
      border-color: #bdbdba;
      border-style: dotted;
      border-collapse: collapse;
      margin-right: auto;
      padding: 0in 5.4pt 0in 5.4pt;
      text-align: left;
    }
  </style>
 <thead><tr><th data-role="resizable">Feature</th><th>Convex</th><th>Firebase</th></tr></thead><tbody><tr><td>Realtime apps</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Datastore / Database</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Cloud functions</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>File storage</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>React support</td><td>✅ Yes</td><td>❌ No</td></tr><tr><td>Relational DB support</td><td>✅ Yes</td><td>❌ No</td></tr><tr><td>Live development environment</td><td>✅ Yes</td><td>❌ No</td></tr><tr><td>Transactions by default</td><td>✅ Yes</td><td>❌ No</td></tr><tr><td>Schema enforcement</td><td>✅ Yes</td><td>❌ No</td></tr></tbody></table><br /><p>However, I find this to be incomplete at best, and incorrect at worst. This is what the table should look like, only keeping those features</p><table><style>table,
 th,
    td {
      border: 1px;
      border-color: #bdbdba;
      border-style: dotted;
      border-collapse: collapse;
      margin-right: auto;
      padding: 0in 5.4pt 0in 5.4pt;
      text-align: left;
    }
  </style>
 <thead><tr><th>Feature</th><th>Convex</th><th>Firebase</th></tr></thead><tbody><tr><td>Realtime apps</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Datastore / Database</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Cloud functions</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>File storage</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>React support</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Relational DB support</td><td>❌ No</td><td>❌ No</td></tr><tr><td>Local Development</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Transactions Support</td><td>✅ Yes</td><td>✅ Yes</td></tr><tr><td>Schema Optional</td><td>✅ Yes</td><td>✅ Yes</td></tr></tbody></table><br /><p>noSQL is NEVER relational, and you can emulate that with either database in different ways. They both have local development, which works differently.</p><p>Transactions and schemas are available in both. React support is definitely available in both, but Convex does <strong>NOT</strong> have first class support for Nuxt or SvelteKit, which I believe is a must these days, especially if you need authentication.</p><p>I would also argue that due to <a target="_blank" href="https://firebase.google.com/docs/firestore/pipelines/get-started-with-pipelines">pipeline operators</a>, Firebase can now handle relationships way better than Convex ever can.</p><h3 id="where-convex-wins">Where Convex Wins</h3><ol><li>TypeScript and React developers-first</li><li>Just write trigger directly in TypeScript</li><li>Better at handling security directly</li><li>Better foreign key and creation time handling</li></ol><h3 id="where-firebase-wins">Where Firebase Wins</h3><ol><li>Very mature ecosystem for support and features</li><li>Handles all frameworks</li><li>Setup is seamless and very easy to use</li><li>Has many querying capabilities and helpers for scaling</li></ol><p> Convex got some traction after <a target="_blank" href="https://t3.gg/">Theo</a> started using it for his <a target="_blank" href="http://t3.chat">t3.chat</a> app. Theo is heavily into React and TypeScript, so this makes sense.</p><h3 id="final">Final</h3><p>Convex seems to prosper where Firebase is lacking. A lot of people don&rsquo;t use <a target="_blank" href="https://firebase.google.com/docs/rules">Firebase Security Rules</a> correctly, or at all, because they are hard to maintain. You get the same problem with <a target="_blank" href="https://supabase.com/docs/guides/database/postgres/row-level-security">Supabase RLS</a>.</p><p>Convex is just TypeScript. The setup is <em>terrible</em>, but the developer experience after that was <em>very intuitive</em> once you understood it. I could see this really helping you build something that scales quickly.</p><p><strong>Firebase still wins for me</strong>, but mainly due to maturity.</p><p>Here is what I would like to see in Convex for it to be a stronger contender for my needs:</p><ul><li>First-class support for SvelteKit, NextJS and Nuxt. Not everyone uses React.</li><li>First-class support for authentication. The code that is written for React only can <em>easily</em> be modified to support all frameworks. The docs need to show setup once complete. This should also include <em>server</em> authentication with cookies etc.</li><li>Convex is a noSQL database and its documentation shouldn&rsquo;t confuse relations. It is not clear how you data model. It is also a plus for Convex how they explain how running multiple <code>await</code> for database calls can be done close to the database in a transaction to emulating a join&hellip; I just wish they didn&rsquo;t confuse it for a join. It is OK that it is noSQL.</li><li>A simplified <code>.env</code> management, as it gets confusing where it lies, especially when with production and development databases as well as local and production hosting.</li><li>Examples for when you don&rsquo;t need real time and you want to load on server only. This is just as important.</li></ul><p>I think as Convex matures it could really be amazing, but it is not quite there if you want everything as plug-and-play as Firebase.</p><p><strong>Repo:</strong> <a target="_blank" href="https://github.com/jdgamble555/nuxt-convex">GitHub</a><br /><strong>Demo:</strong> <a target="_blank" href="https://nuxt-convex-seven.vercel.app/">Vercel Functions</a></p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">Best Graph Databases in 2026</h4></div><div class="col-8"><p class="u-fs16 u-mb0">One developer weighs <a target="_blank" href="https://www.telerik.com/blogs/best-graph-databases-2026">pros and cons of graph databases</a> and shares his insights into what works best for various use cases.</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17524028.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:c4a5df39-5494-4923-b6c5-431509d94a96</id>
    <title type="text">A Better v-model with defineModel</title>
    <summary type="text">Rather than three separate pieces for a two-way bound value, defineModel gives this common Vue component pattern a single line of syntax.</summary>
    <published>2026-11-12T17:34:58Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Marina Mosti </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17522982/better-v-model-definemodel"/>
    <content type="text"><![CDATA[<p><span class="featured">Rather than three separate pieces for a two-way bound value, defineModel gives this common Vue component pattern a single line of syntax.</span></p><p>In my previous article on <a target="_blank" href="https://www.telerik.com/blogs/vue-basics-script-setup-sugar">Vue Basics: Script Setup Sugar</a>, we went through the five compiler macros that make <code>&lt;script setup&gt;</code> so pleasant to work with. <code>defineModel</code> got a section there, but it was sharing the page with four other macros. I also said outright that the <code>v-model</code> syntax itself was out of scope for that piece. This post is that missing piece.</p><p>If you&rsquo;ve been writing Vue components for a while, you know the ritual. You want a custom input component that works with <code>v-model</code>, so you declare a <code>modelValue</code> prop, declare an <code>update:modelValue</code> emit, and then write a little computed property or a handler to glue the two together. That&rsquo;s three moving parts for one simple idea. A value flows into your component, and it flows back out.</p><p><code>defineModel</code> collapses all of that into a single line. It landed as a stable feature in Vue 3.4, and today I want to walk through how it works, what it compiles down to, how to handle multiple bindings and modifiers, and the one gotcha that will bite you if nobody warns you about it.</p><h2 id="what-is-definemodel">What Is defineModel?</h2><p><code>defineModel</code> is a compiler macro, the same family as <code>defineProps</code> and <code>defineEmits</code>. You call it inside <code>&lt;script setup&gt;</code>, and it hands you back a ref.</p><p>That ref is special. Reading it gives you the value the parent passed down. Writing to it tells the parent to update. You never touch <code>emit</code> directly.</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token function">defineModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><p>Behind the scenes, the compiler turns that one line into a prop named <code>modelValue</code> and an emit named <code>update:modelValue</code>. When you do <code>model.value = 'draft'</code>, the emit fires with that string as the payload. The parent&rsquo;s <code>v-model</code> picks it up and updates its own state, which flows back down as the prop.</p><p>So there&rsquo;s nothing new happening underneath. It&rsquo;s the same prop and event pair Vue has always used for component <code>v-model</code>. The difference is that Vue writes it for you.</p><h2 id="the-way-we-used-to-do-it">The Way We Used to Do It</h2><p>Let&rsquo;s look at a text input wrapper written the pre-3.4 way, because the difference is easier to see side by side.</p><p><code>BaseInput.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
const props = defineProps({
  modelValue: {
    type: String,
  },
})

const emit = defineEmits(['update:modelValue'])

const handleInput = (event) =&gt; {
  emit('update:modelValue', event.target.value)
}
&lt;/script&gt;

&lt;template&gt;
  &lt;input :value="props.modelValue" @input="handleInput" /&gt;
&lt;/template&gt;
</code></pre><p>That works, and plenty of production apps are still full of components shaped exactly like this. There&rsquo;s nothing wrong with it!</p><p>But notice how much of it is simply fluff. The prop name and the emit name have to match a convention you&rsquo;re expected to remember.</p><p>And a big one, you can&rsquo;t use <code>v-model</code> on the inner <code>&lt;input&gt;</code> because you&rsquo;re not allowed to mutate a prop, so you fall back to <code>:value</code> plus <code>@input</code>.</p><p>You&rsquo;ve probably seen the alternative version of this too, the <a target="_blank" href="https://vuejs.org/guide/essentials/computed.html#writable-computed">writable computed</a> that people reach for so they can write to the value again:</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">import</span> <span class="token punctuation">{</span> computed <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> props <span class="token operator">=</span> <span class="token function">defineProps</span><span class="token punctuation">(</span><span class="token punctuation">{</span> modelValue<span class="token punctuation">:</span> <span class="token punctuation">{</span> type<span class="token punctuation">:</span> String <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> emit <span class="token operator">=</span> <span class="token function">defineEmits</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string">'update:modelValue'</span><span class="token punctuation">]</span><span class="token punctuation">)</span>

<span class="token keyword">const</span> localValue <span class="token operator">=</span> <span class="token function">computed</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token keyword">get</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> props<span class="token punctuation">.</span>modelValue<span class="token punctuation">,</span>
  <span class="token keyword">set</span><span class="token punctuation">:</span> <span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token function">emit</span><span class="token punctuation">(</span><span class="token string">'update:modelValue'</span><span class="token punctuation">,</span> value<span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><p>Clever, but it&rsquo;s still four extra lines and one more thing to decode every time you read the component.</p><h2 id="the-same-component-with-definemodel">The Same Component with defineModel</h2><p>Here&rsquo;s the whole thing again.</p><p><code>BaseInput.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
const model = defineModel({ type: String })
&lt;/script&gt;

&lt;template&gt;
  &lt;input v-model="model" /&gt;
&lt;/template&gt;
</code></pre><p>Let&rsquo;s break it down. <code>defineModel</code> declares the <code>modelValue</code> prop and the <code>update:modelValue</code> emit in one shot. The options object takes the prop options you already know from <code>defineProps</code>. <code>type</code> and <code>required</code> behave exactly the same way, and <code>default</code> has one wrinkle we&rsquo;ll get to shortly. It also takes two extra options, <code>get</code> and <code>set</code>, which we&rsquo;ll cover in the modifiers section.</p><p>The return value is a writable ref, which means we can hand it straight to <code>v-model</code> on the native input. No <code>:value</code>, no <code>@input</code>, no computed with a setter. When the user types, <code>v-model</code> writes to <code>model</code>, writing to <code>model</code> emits the update, and the parent sees the new value.</p><p>A parent that uses this doesn&rsquo;t change at all; it is unaware of the inner workings of the component:</p><p><code>SignupForm.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { ref } from 'vue'
import BaseInput from './BaseInput.vue'

const email = ref('')
&lt;/script&gt;

&lt;template&gt;
  &lt;BaseInput v-model="email" /&gt;
  &lt;p&gt;You typed: {{ email }}&lt;/p&gt;
&lt;/template&gt;
</code></pre><p>That&rsquo;s the part I like most about this macro. It only changes how you write the child. Nothing about the parent changes, so every component that already uses yours keeps working, and you can migrate file by file whenever you happen to be in there.</p><h2 id="required-default-and-the-gotcha">Required, Default and the Gotcha</h2><p>You can mark a model as required, which is genuinely useful for components that make no sense without a value:</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> status <span class="token operator">=</span> <span class="token function">defineModel</span><span class="token punctuation">(</span><span class="token punctuation">{</span> required<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><p>You can also give it a default:</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> status <span class="token operator">=</span> <span class="token function">defineModel</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token keyword">default</span><span class="token punctuation">:</span> <span class="token string">'draft'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><p>⚠️ Keep this in mind!</p><p>Defaults on a model aren&rsquo;t the same as defaults on a normal prop. If the parent binds a ref that happens to be <code>undefined</code>, the child will use its default of <code>'draft'</code>, but the parent&rsquo;s ref stays <code>undefined</code>. The two sides are now showing different values and nothing has told you about it. The child thinks the status is a draft; the parent thinks there&rsquo;s no status at all.</p><p>The <a target="_blank" href="https://vuejs.org/api/sfc-script-setup.html#definemodel">official docs flag this too</a>, and my personal rule is simple. If a component is going to declare a default for its model, I initialize the parent ref with a real value instead of leaving it empty. Let the parent own the starting state, and use the child default only as a safety net.</p><p>For objects and arrays, wrap the default in a function the same way you would for any other prop:</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> tags <span class="token operator">=</span> <span class="token function">defineModel</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token keyword">default</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><h2 id="multiple-v-model-bindings">Multiple v-model Bindings</h2><p><code>v-model</code> takes an argument, which means one component can expose more than one two-way binding. Pass the prop name as the first argument to <code>defineModel</code> and you get a separate ref for each one. This has to be a plain string since the macro runs at build time, so a variable would have no value to read yet.</p><p><code>DateRangePicker.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
const startDate = defineModel('startDate', { type: String })
const endDate = defineModel('endDate', { type: String })
&lt;/script&gt;

&lt;template&gt;
  &lt;input type="date" v-model="startDate" /&gt;
  &lt;input type="date" v-model="endDate" /&gt;
&lt;/template&gt;
</code></pre><p>And the parent binds each one by name:</p><p><code>ReportFilters.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { ref } from 'vue'
import DateRangePicker from './DateRangePicker.vue'

const from = ref('2026-01-01')
const to = ref('2026-01-31')
&lt;/script&gt;

&lt;template&gt;
  &lt;DateRangePicker v-model:start-date="from" v-model:end-date="to" /&gt;
&lt;/template&gt;
</code></pre><p>Notice the casing. In the template we write <code>v-model:start-date</code> in kebab-case, and in the child we declare <code>defineModel('startDate')</code> in camelCase. Vue handles the conversion for props the same way it always has, so both spellings refer to the same thing.</p><p>Date ranges are the case I hit most often, along with min/max sliders and address blocks. Anything where the component genuinely owns several related values, and where one object prop would be worse. The parent would have to spread the whole object just to change one field.</p><p>To be quite honest with you, I try not to go past two or three models on a single component. If you find yourself with more than two, usually it signals that the component is doing too much and wants to be split, or the data really is one object and should travel as one.</p><h2 id="modifiers-without-the-pain">Modifiers Without the Pain</h2><p>Custom <code>v-model</code> modifiers are one of those Vue features almost nobody used before 3.4, and I&rsquo;m fairly sure the reason was that wiring them up was tedious. You had to declare a second prop with a very specific name, default it to an empty object and check it by hand.</p><p>With <code>defineModel</code>, you destructure the return value into a pair. The first element is the ref. The second is the modifiers object.</p><p><code>SlugInput.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
const [model, modifiers] = defineModel({
  set(value) {
    if (modifiers.slug &amp;&amp; value) {
      // Transform a string like "Hello world" into "hello-world"
      return value.toLowerCase().replace(/\s+/g, '-')
    }
    return value
  },
})
&lt;/script&gt;

&lt;template&gt;
  &lt;input v-model="model" /&gt;
&lt;/template&gt;
</code></pre><p>The parent opts in with a dot:</p><p><code>ArticleForm.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
import { ref } from 'vue'
import SlugInput from './SlugInput.vue'

const slug = ref('')
&lt;/script&gt;

&lt;template&gt;
  &lt;SlugInput v-model.slug="slug" /&gt;
&lt;/template&gt;
</code></pre><p>Let&rsquo;s break down what&rsquo;s happening. The <code>set</code> option is a transformer that runs on the way out, right before the value is emitted to the parent.</p><p>Inside it we check <code>modifiers.slug</code>, which is <code>true</code> only when the parent wrote <code>.slug</code> on the binding. If it&rsquo;s there, we lowercase the text and swap spaces for hyphens. Otherwise, we pass the value through untouched.</p><p>Notice the <code>&amp;&amp; value</code> guard. The <code>set</code> option runs on every write, including writes you make yourself from inside the component. If a reset somewhere does <code>model.value = null</code>, the transformer would try to call <code>toLowerCase</code> on it and throw. It&rsquo;s a tiny guard and it stops that crash.</p><p>Keep in mind that <code>set</code> never runs when you read the model, so it does nothing on first render. If you want the same protection when reading, that&rsquo;s what <code>get</code> is for.</p><p>There&rsquo;s a matching <code>get</code> option that transforms on the way in, when you read the model ref inside the child. It&rsquo;s good for cleaning up a value so your template doesn&rsquo;t have to keep checking it:</p><p><code>SearchInput.vue</code></p><pre class=" language-vue"><code class="prism  language-vue">&lt;script setup&gt;
const query = defineModel({
  type: String,
  get: (value) =&gt; value ?? '',
})
&lt;/script&gt;

&lt;template&gt;
  &lt;input v-model="query" /&gt;
  &lt;p&gt;{{ query.length }} characters&lt;/p&gt;
&lt;/template&gt;
</code></pre><p>The parent is free to hold <code>null</code> or leave the ref empty, and everything inside the child can treat the value as a string. This is a mild version of the mismatch I warned about earlier, since the child shows an empty string while the parent still holds <code>null</code>. It&rsquo;s much tamer than inventing a default value, and the first keystroke puts both sides back in step.</p><p>One important caveat here.</p><p>A <code>get</code> should never change a value the user actually typed. It runs on every read, so anything that reshapes real input will fight the user as they type.</p><p>The example above is safe because <code>?? ''</code> only steps in when there&rsquo;s nothing there. Any string the user types passes through untouched.</p><p>Now, say you write a <code>get</code> that rounds a number to two decimals instead. It looks fine in a demo, but <code>get</code> runs every single time the value is read, so it reformats the number right back into the field. Type <code>12.567</code> and the field rewrites itself under you while you&rsquo;re still typing.</p><p>Filling in a missing value is fine. Reformatting a real one is not.</p><p>For named models, the modifiers come back from that specific model&rsquo;s own destructure:</p><pre class=" language-javascript"><code class="prism  language-javascript"><span class="token keyword">const</span> <span class="token punctuation">[</span>startDate<span class="token punctuation">,</span> startModifiers<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">defineModel</span><span class="token punctuation">(</span><span class="token string">'startDate'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> <span class="token punctuation">[</span>endDate<span class="token punctuation">,</span> endModifiers<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">defineModel</span><span class="token punctuation">(</span><span class="token string">'endDate'</span><span class="token punctuation">)</span>
</code></pre><p>Write <code>v-model:start-date.iso</code> on the parent and only <code>startModifiers</code> sees <code>{ iso: true }</code>. The other model&rsquo;s modifiers object stays empty.</p><h2 id="typescript">TypeScript</h2><p>If you&rsquo;re working in TypeScript, <code>defineModel</code> takes a type parameter.</p><pre class=" language-typescript"><code class="prism  language-typescript"><span class="token keyword">const</span> amount <span class="token operator">=</span> defineModel<span class="token operator">&lt;</span><span class="token keyword">number</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><p>That gives you <code>Ref&lt;number | undefined&gt;</code>, because nothing guarantees the parent passed anything. Mark it required and the <code>undefined</code> goes away:</p><pre class=" language-typescript"><code class="prism  language-typescript"><span class="token keyword">const</span> amount <span class="token operator">=</span> defineModel<span class="token operator">&lt;</span><span class="token keyword">number</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">{</span> required<span class="token punctuation">:</span> <span class="token keyword">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre><p>Modifier names can be typed too, with a second type parameter as a union of the modifier strings you support:</p><pre class=" language-typescript"><code class="prism  language-typescript"><span class="token keyword">const</span> <span class="token punctuation">[</span>amount<span class="token punctuation">,</span> modifiers<span class="token punctuation">]</span> <span class="token operator">=</span> defineModel<span class="token operator">&lt;</span><span class="token keyword">number</span><span class="token punctuation">,</span> <span class="token string">'rounded'</span><span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre><p>Now <code>modifiers.rounded</code> type checks and a typo like <code>modifiers.rounde</code> does not. This is a small thing, but it&rsquo;s the kind of small thing that saves you a confused 10 minutes.</p><h2 id="when-not-to-reach-for-a-definemodel">When Not to Reach for a defineModel</h2><p><code>defineModel</code> makes two-way binding so cheap to write that it&rsquo;s tempting to put one on everything.</p><p>A model is the right shape when the parent owns a value and the child is a nicer way to edit it. Inputs, selects, toggles, pickers, editors. The child has no opinion about the value beyond how it&rsquo;s displayed and changed.</p><p>It&rsquo;s the wrong shape when the child is really reporting something rather than editing something. If a component is telling the parent &ldquo;the user scrolled past this point&rdquo; or &ldquo;validation failed,&rdquo; that&rsquo;s an event, not a model. Use <code>defineEmits</code> and say what happened. Two-way binding there just gives the parent a piece of state it has no business writing to.</p><h2 id="migrating-an-existing-component">Migrating an Existing Component</h2><p>If you have a codebase full of the old shape, the swap is mechanical. Delete the <code>modelValue</code> entry from <code>defineProps</code>, delete <code>update:modelValue</code> from <code>defineEmits</code>, delete the handler or the computed, and add one <code>defineModel</code> call. Then replace <code>:value</code> plus <code>@input</code> in the template with a plain <code>v-model</code>.</p><p>Two things to watch for while you do it:</p><ul><li><strong>Other props</strong>: If your component had props alongside <code>modelValue</code>, keep the <code>defineProps</code> call for those and just remove the model entry. <code>defineModel</code> and <code>defineProps</code> live happily in the same file, they just can&rsquo;t declare the same prop name twice.</li><li><strong>Other emit sites</strong>: If you were emitting <code>update:modelValue</code> from somewhere other than the input handler, say inside a reset method, that becomes a plain assignment like <code>model.value = ''</code>.</li></ul><p>One last thing before you start. <code>defineModel</code> is 3.4 and up, and the modifier destructuring shape is part of that same release. If you&rsquo;re stuck on an older 3.x for whatever reason, the props-and-emit version is still completely valid Vue and there&rsquo;s no urgency to rewrite anything. This is a quality-of-life feature, not a correctness fix.</p><h2 id="wrapping-up">Wrapping Up</h2><p><code>defineModel</code> takes the most common component pattern in Vue, the two-way bound value, and gives it a single line of syntax instead of three separate pieces. You get a writable ref you can pass straight to <code>v-model</code>, prop options you already know, named models for components with several bindings and modifier support that&rsquo;s finally worth using.</p><p>The <a target="_blank" href="https://vuejs.org/api/sfc-script-setup.html#definemodel">defineModel API reference</a> and the <a target="_blank" href="https://vuejs.org/guide/components/v-model.html">Component v-model guide</a> both have more detail, especially around the transformer options.</p><p>Happy v-modeling!</p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">Vue Basics: Understanding useId in Vue 3</h4></div><div class="col-8"><p class="u-fs16 u-mb0">Learn how to use <a target="_blank" href="https://www.telerik.com/blogs/vue-basics-understanding-useid-vue-3">useId in Vue 3</a> to generate stable, unique IDs for reusable components, improve accessibility and avoid SSR hydration issues.</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17522982.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:3e51f582-8627-430d-82f4-72bf94072830</id>
    <title type="text">Ready for .NET 11: Day-Zero Support Across the Telerik Portfolio</title>
    <summary type="text">The Progress Telerik portfolio of products is ready for .NET 11 support so you won’t miss a step.</summary>
    <published>2026-11-11T21:37:24Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Iva Borisova </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17522403/ready-net-11-day-zero-support-across-telerik-portfolio"/>
    <content type="text"><![CDATA[<p><span class="featured">The Progress Telerik portfolio of products is ready for .NET 11 support so you won&rsquo;t miss a step.</span></p><p>With Microsoft&rsquo;s .NET 11 release, Progress is shipping Telerik products with day-zero support for .NET 11. Development teams can start exploring the latest platform improvements immediately and move to production on their own schedule.</p><p>Each new .NET release brings improvements across the runtime, developer tooling and application frameworks. .NET 11 continues that work with updates for web and cross-platform development. Telerik customers can adopt the new platform and continue using the Telerik tools they rely on across their application stack.</p><h2 id="net-11-support-across-telerik-products">.NET 11 Support Across Telerik Products</h2><p>Every major Telerik UI library, reporting, document processing and mocking solution is ready from day one. Whether you&rsquo;re building web, desktop, mobile or document-processing workflows, you can upgrade with confidence and continue using the Telerik solutions you rely on today.</p><ul><li><a target="_blank" href="https://www.telerik.com/blazor-ui">Telerik UI for Blazor</a> is compatible with .NET 11.</li><li><a target="_blank" href="https://www.telerik.com/aspnet-core-ui">Telerik UI for ASP.NET Core</a> is compatible with .NET 11 and can be used alongside the platform improvements without requiring corresponding changes to Telerik components.</li><li><a target="_blank" href="https://www.telerik.com/maui-ui">Telerik UI for .NET MAUI</a> supports .NET 11 from day one.</li><li><a target="_blank" href="https://www.telerik.com/products/winforms.aspx">Telerik UI for WinForms</a>,&nbsp;<a target="_blank" href="https://www.telerik.com/products/wpf/overview.aspx">Telerik UI for WPF</a>&nbsp;and <a target="_blank" href="https://www.telerik.com/aspnet-mvc">Telerik UI for ASP.NET MVC</a> are compatible with .NET 11.</li><li><a target="_blank" href="https://www.telerik.com/products/reporting.aspx">Telerik Reporting</a> is compatible with .NET 11. While the release includes runtime-level async improvements, the Reporting engine is not heavily async-based, so we do not expect those changes to have a significant performance impact on the engine.</li><li><a target="_blank" href="https://www.telerik.com/document-processing-libraries">Telerik Document Processing Libraries</a> are compatible with .NET 11.</li><li>Telerik Visual Studio and Visual Studio Code extensions support .NET 11 development workflows.</li><li><a target="_blank" href="https://www.telerik.com/products/mocking.aspx">Telerik JustMock</a> supports .NET 11 Runtime Async scenarios.</li></ul><h2 id="what-.net-11-brings-to-blazor">What .NET 11 Brings to Blazor</h2><p>.NET 11 brings a wide range of Blazor improvements. Here are a few highlights we picked because they are especially relevant to apps built with Telerik UI for Blazor components:</p><ul><li>The new <a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis#new-displayname-component-and-support-for-display-and-displayname-attributes">DisplayName component and support for Display and DisplayName attributes</a> make it easier to show a field&rsquo;s display name, for example, in a <code>&lt;label&gt;</code> within a <a target="_blank" href="https://www.telerik.com/blazor-ui/documentation/components/form/formitems/template">Telerik Form item template</a>.</li><li><a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis#asynchronous-form-validation-support">Asynchronous form validation</a> supports validation workflows that depend on asynchronous value checks.</li><li><a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis#client-side-prerendering-in-a-blazor-web-app-preserves-the-servers-culture">Client-side prerendering preserves the server&rsquo;s culture</a>, helping maintain consistent localized output.</li><li>A <a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis#new-development-server-for-blazor-webassembly-apps">new development server for Blazor WebAssembly apps</a> brings an updated development experience.</li><li><a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis#server-triggered-circuit-pause">Server-triggered circuit pause</a> and <a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis#automatic-circuit-pause-on-tab-inactivity">automatic circuit pause on tab inactivity</a> give apps more ways to manage resources for inactive Blazor Server sessions.</li></ul><p>These are framework-level capabilities you can use in any Blazor app, and they work hand in hand with <a target="_blank" href="https://www.telerik.com/blazor-ui">Telerik UI for Blazor</a>. Because the library supports a broad range of .NET versions, the same Telerik package works across your .NET 10 and .NET 11 projects, so you can adopt the latest framework features at your own pace.</p><p>For more details, see Microsoft&rsquo;s <a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-11?view=aspnetcore-10.0&amp;tabs=minimal-apis">ASP.NET Core 11 release notes</a>.</p><h2 id="net-maui-11-unified-runtime-faster-builds-higher-quality">.NET MAUI 11: Unified Runtime, Faster Builds, Higher Quality</h2><p>With .NET 11, Microsoft is putting the emphasis on .NET MAUI quality while continuing to modernize the framework underneath. The move to CoreCLR, improvements to XAML compilation and Native AOT support bring .NET MAUI closer to the rest of the .NET platform, giving developers a more consistent runtime and development experience.</p><h3 id="runtime-and-performance">Runtime and Performance</h3><ul><li><strong>CoreCLR becomes the default runtime</strong> for Android, iOS, Mac Catalyst and tvOS, replacing Mono and bringing .NET MAUI onto the same runtime foundation as the rest of .NET. The change opens the door to improvements in debugging, profiling, Hot Reload and runtime performance. Learn more in <a target="_blank" href="https://devblogs.microsoft.com/dotnet/dotnet-maui-moves-to-coreclr-in-dotnet-11/">.NET MAUI Moves to CoreCLR in .NET 11</a>.</li><li><strong>Native AOT publishing</strong> is available as an opt-in option for scenarios where startup performance and application size are important.</li></ul><h3 id="developer-experience">Developer Experience</h3><ul><li><strong>XAML source generation is now the default</strong>, moving XAML compilation to source generation and helping improve build performance while bringing Debug and Release builds closer together.</li><li><strong>HybridWebView gets better Native AOT and trimming support</strong> through source-generated JSON serialization for JavaScript-to-.NET calls, making hybrid applications better suited for fully trimmed and AOT-compiled deployments.</li></ul><h3 id="platform-alignment">Platform Alignment</h3><ul><li><strong>Material 3 support on Android</strong> brings .NET MAUI applications in line with Google&rsquo;s latest Material design system and modern Android experiences.</li><li><strong>Xcode 27 readiness</strong> helps developers prepare existing Apple applications for platform changes, including the updated scene lifecycle.</li></ul><p>The result? A more unified .NET foundation, quicker development cycles and better alignment with the platforms your apps run on.</p><p>With <a target="_blank" href="https://www.telerik.com/maui-ui">Telerik UI for .NET MAUI</a> supporting .NET 11 from day one, developers can take advantage of the new runtime and tooling improvements while continuing to build polished, production-ready cross-platform experiences.</p><p>For the full list of changes, see <a target="_blank" href="https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-11">What&rsquo;s new in .NET MAUI for .NET 11</a>.</p><h2 id="justmock-and-runtime-async">JustMock and Runtime Async</h2><p>.NET 11 advances <a target="_blank" href="https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-11/overview">Runtime Async</a>, a runtime-managed approach to asynchronous execution that changes how some async methods are represented and executed. Instead of relying on the traditional compiler-generated state machine, these methods use a runtime-managed model.</p><p>The JustMock CodeWeaver profiler detects Runtime Async methods during JIT compilation and uses a dedicated interception path at async suspension and resumption points. Methods that continue to use the traditional compiler-generated state machine remain supported through the existing JustMock interception path. The profiler also excludes runtime async helper intrinsics from instrumentation to prevent recursive profiling.</p><p>This means teams can continue using <a target="_blank" href="https://www.telerik.com/products/mocking.aspx">Telerik JustMock</a> for asynchronous scenarios on .NET 11, including <code>Task&lt;T&gt;</code>, <code>ValueTask&lt;T&gt;</code> and static async methods, as well as exception propagation across async suspension boundaries.</p><h2 id="plan-your-next-upgrade">Plan Your Next Upgrade</h2><p>Microsoft has scheduled the end of support for <strong>.NET 8 and .NET 9 for November 10, 2026</strong>, and support for <strong>.NET Framework 4.6.2 is scheduled to end on January 12, 2027</strong>. While these dates are set by Microsoft, Progress will continue to support these versions in Telerik products until February 2027. This additional window is designed to allow a smooth transition for teams still running on .NET 8 or .NET 9, giving them enough time to plan and complete their migration without disruption.</p><p>If your applications still target these frameworks, now is a good time to review your upgrade plans. Refer to Microsoft&rsquo;s <a target="_blank" href="https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core">.NET and .NET Core support policy</a>, <a target="_blank" href="https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-framework">.NET Framework support policy</a>, <a target="_blank" href="https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework">.NET Framework lifecycle page</a> and the announcement that <a target="_blank" href="https://devblogs.microsoft.com/dotnet/dotnet-8-9-end-of-support/">.NET 8 and .NET 9 will reach end of support on November 10, 2026</a>.</p><p>Whether you&rsquo;re modernizing existing applications or starting new projects, .NET 11 provides the latest platform capabilities while Telerik delivers the UI, reporting, mocking and document-processing tools you need to build production-ready applications from day one.</p><img src="https://feeds.telerik.com/link/10827/17522403.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:cf263156-c640-4332-ab8a-20f0c03208a8</id>
    <title type="text">QR Codes and Barcodes: Real-World Use Cases in Blazor</title>
    <summary type="text">See how to use QR codes and barcodes together in a real use case of an event-ticketing Blazor application, plus checking in the ticket at the event.</summary>
    <published>2026-11-10T18:13:31Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Héctor Pérez </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17521717/qr-codes-barcodes-real-world-use-cases-blazor"/>
    <content type="text"><![CDATA[<p><span class="featured">See how to use QR codes and barcodes together in a real use case of an event-ticketing Blazor application, plus checking in the ticket at the event.</span></p><p>QR codes and barcodes are among the most-used elements in the digital and physical world, and we interact with them daily. They serve to identify product prices in a supermarket, to show updated menus to customers in a restaurant and even to identify a boarding pass for an airplane.</p><p>That&rsquo;s why in this post, we&rsquo;ll see how the <a target="_blank" href="https://www.telerik.com/blazor-ui/barcode">Blazor Barcode</a> and <a target="_blank" href="https://www.telerik.com/blazor-ui/qr-code">Blazor QR Code</a> components from Progress Telerik can help you represent information visually with ease. Let&rsquo;s get started!</p><h2 id="what-are-qr-codes-and-barcodes">What Are QR Codes and Barcodes?</h2><p>Although we constantly use QR codes and barcodes, have you ever wondered what the difference between them is? Well, in short, the difference lies in how many dimensions are used to store data:</p><ul><li>A one-dimensional (1D) <strong>barcode</strong> stores information using a set of bars and spaces of varying width. It is ideal for short values, such as a serial number or identifier, as is done with supermarket products.</li><li><strong>QR codes</strong>, which are 2D or two-dimensional, store information in a grid of white and black modules. Because they use the vertical and horizontal axes, much more information can be stored. In addition, the standard defines levels that allow a QR code to be read even if it is damaged or partially obscured.</li></ul><p>A common question is when to use one over the other. The answer is that it is ideal to use barcodes when you need to represent a short identifier, and to reserve QR codes for when you need to encode things like URLs or contact information.</p><h2 id="creating-a-blazor-application-using-barcodes-and-qr">Creating a Blazor Application Using Barcodes and QR</h2><p>Let&rsquo;s see how to use the fabulous Telerik components to create an application that issues event tickets, composed of different sections to display ticket information, view generated tickets and perform check-in for the event.</p><h3 id="integrating-telerik-components-into-a-blazor-web-project">Integrating Telerik Components into a Blazor Web Project</h3><p>To use Telerik components, we must install them if we already have a Blazor project created, for which we can use the <a target="_blank" href="https://www.telerik.com/blazor-ui/documentation/getting-started/workflow-details">installation guide</a>. If you want to start from scratch, you can use a <a target="_blank" href="https://www.telerik.com/blazor-ui/documentation/getting-started/web-app#set-up-telerik-development-environment">prebuilt template</a> and integrate it into VS 2026, with everything needed to get to work immediately.</p><h3 id="creating-the-model-for-the-ticketing-system">Creating the Model for the Ticketing System</h3><p>To manage tickets for the simulated event, we will create a new model called <code>Ticket</code>, which will look as follows:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Ticket</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> Code <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">string</span><span class="token punctuation">.</span>Empty<span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">long</span> BarcodeNumber <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> AttendeeName <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">string</span><span class="token punctuation">.</span>Empty<span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> Email <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">string</span><span class="token punctuation">.</span>Empty<span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> TicketType <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">string</span><span class="token punctuation">.</span>Empty<span class="token punctuation">;</span>
    <span class="token keyword">public</span> DateTime IssuedAt <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">bool</span> CheckedIn <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> DateTime<span class="token operator">?</span> CheckedInAt <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>In the model above, we defined the property <code>Code</code>, which will be the encoded value for the QR code URL, while the property <code>BarcodeNumber</code> is the short number to store the barcode value. The other data will be used to store attendee data as well as check-in information.</p><h3 id="creating-a-service-for-the-ticketing-system">Creating a Service for the Ticketing System</h3><p>With the model ready, it&rsquo;s time to create the service that will handle the app logic, including issuing tickets, building the validation URL and performing the check-in process. Let&rsquo;s create the new class called <code>TicketService</code>:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token comment">//1.</span>
<span class="token keyword">public</span> <span class="token keyword">enum</span> CheckInStatus
<span class="token punctuation">{</span>
    Success<span class="token punctuation">,</span>
    AlreadyCheckedIn<span class="token punctuation">,</span>
    NotFound
<span class="token punctuation">}</span>

<span class="token comment">//2.</span>
<span class="token keyword">public</span> record <span class="token function">CheckInResult</span><span class="token punctuation">(</span>CheckInStatus Status<span class="token punctuation">,</span> Ticket<span class="token operator">?</span> Ticket<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//3.</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TicketService</span>
<span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">const</span> <span class="token keyword">string</span> DefaultValidationBaseUrl <span class="token operator">=</span> <span class="token string">"https://tickets.hector-events.com/validate"</span><span class="token punctuation">;</span>

    <span class="token keyword">private</span> <span class="token keyword">readonly</span> <span class="token keyword">string</span> _validationBaseUrl<span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">readonly</span> List<span class="token operator">&lt;</span>Ticket<span class="token operator">&gt;</span> _tickets <span class="token operator">=</span> <span class="token keyword">new</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span> _sequence <span class="token operator">=</span> <span class="token number">1000</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">TicketService</span><span class="token punctuation">(</span>IConfiguration configuration<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        _validationBaseUrl <span class="token operator">=</span> configuration<span class="token punctuation">[</span><span class="token string">"Tickets:ValidationBaseUrl"</span><span class="token punctuation">]</span> <span class="token operator">?</span><span class="token operator">?</span> DefaultValidationBaseUrl<span class="token punctuation">;</span>

        <span class="token function">IssueTicket</span><span class="token punctuation">(</span><span class="token string">"Laura Geek"</span><span class="token punctuation">,</span> <span class="token string">"laura@company1.com"</span><span class="token punctuation">,</span> <span class="token string">"VIP"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">IssueTicket</span><span class="token punctuation">(</span><span class="token string">"Alan Valley"</span><span class="token punctuation">,</span> <span class="token string">"alan@company2.com"</span><span class="token punctuation">,</span> <span class="token string">"Speaker"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">IssueTicket</span><span class="token punctuation">(</span><span class="token string">"Peter Nerd"</span><span class="token punctuation">,</span> <span class="token string">"peter@company3.com"</span><span class="token punctuation">,</span> <span class="token string">"General Admission"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> IReadOnlyList<span class="token operator">&lt;</span>Ticket<span class="token operator">&gt;</span> Tickets <span class="token operator">=</span><span class="token operator">&gt;</span> _tickets<span class="token punctuation">;</span>

    <span class="token comment">//4.</span>
    <span class="token keyword">public</span> <span class="token keyword">event</span> Action<span class="token operator">?</span> TicketsChanged<span class="token punctuation">;</span>

    <span class="token comment">//5.</span>
    <span class="token keyword">public</span> Ticket <span class="token function">IssueTicket</span><span class="token punctuation">(</span><span class="token keyword">string</span> attendeeName<span class="token punctuation">,</span> <span class="token keyword">string</span> email<span class="token punctuation">,</span> <span class="token keyword">string</span> ticketType<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">var</span> number <span class="token operator">=</span> Interlocked<span class="token punctuation">.</span><span class="token function">Increment</span><span class="token punctuation">(</span><span class="token keyword">ref</span> _sequence<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">var</span> ticket <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Ticket</span>
        <span class="token punctuation">{</span>
            Code <span class="token operator">=</span> $<span class="token string">"TKT-{DateTime.Now.Year}-{number:D6}"</span><span class="token punctuation">,</span>
            BarcodeNumber <span class="token operator">=</span> number<span class="token punctuation">,</span>
            AttendeeName <span class="token operator">=</span> attendeeName<span class="token punctuation">,</span>
            Email <span class="token operator">=</span> email<span class="token punctuation">,</span>
            TicketType <span class="token operator">=</span> ticketType<span class="token punctuation">,</span>
            IssuedAt <span class="token operator">=</span> DateTime<span class="token punctuation">.</span>Now
        <span class="token punctuation">}</span><span class="token punctuation">;</span>

        _tickets<span class="token punctuation">.</span><span class="token function">Insert</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> ticket<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> ticket<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment">//6.</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> <span class="token function">BuildValidationUrl</span><span class="token punctuation">(</span>Ticket ticket<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> $<span class="token string">"{_validationBaseUrl}/{ticket.Code}"</span><span class="token punctuation">;</span>

    <span class="token comment">//7.</span>
    <span class="token keyword">public</span> CheckInResult <span class="token function">CheckIn</span><span class="token punctuation">(</span><span class="token keyword">string</span> scannedValue<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">var</span> <span class="token keyword">value</span> <span class="token operator">=</span> scannedValue<span class="token punctuation">.</span><span class="token function">Trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">var</span> ticket <span class="token operator">=</span> _tickets<span class="token punctuation">.</span><span class="token function">FirstOrDefault</span><span class="token punctuation">(</span>t <span class="token operator">=</span><span class="token operator">&gt;</span>
            <span class="token keyword">string</span><span class="token punctuation">.</span><span class="token function">Equals</span><span class="token punctuation">(</span>t<span class="token punctuation">.</span>Code<span class="token punctuation">,</span> <span class="token keyword">value</span><span class="token punctuation">,</span> StringComparison<span class="token punctuation">.</span>OrdinalIgnoreCase<span class="token punctuation">)</span> <span class="token operator">||</span>
            t<span class="token punctuation">.</span>BarcodeNumber<span class="token punctuation">.</span><span class="token function">ToString</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token keyword">value</span> <span class="token operator">||</span>
            <span class="token keyword">string</span><span class="token punctuation">.</span><span class="token function">Equals</span><span class="token punctuation">(</span><span class="token function">BuildValidationUrl</span><span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">value</span><span class="token punctuation">,</span> StringComparison<span class="token punctuation">.</span>OrdinalIgnoreCase<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>ticket <span class="token keyword">is</span> <span class="token keyword">null</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">CheckInResult</span><span class="token punctuation">(</span>CheckInStatus<span class="token punctuation">.</span>NotFound<span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>ticket<span class="token punctuation">.</span>CheckedIn<span class="token punctuation">)</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">CheckInResult</span><span class="token punctuation">(</span>CheckInStatus<span class="token punctuation">.</span>AlreadyCheckedIn<span class="token punctuation">,</span> ticket<span class="token punctuation">)</span><span class="token punctuation">;</span>

        ticket<span class="token punctuation">.</span>CheckedIn <span class="token operator">=</span> <span class="token keyword">true</span><span class="token punctuation">;</span>
        ticket<span class="token punctuation">.</span>CheckedInAt <span class="token operator">=</span> DateTime<span class="token punctuation">.</span>Now<span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">CheckInResult</span><span class="token punctuation">(</span>CheckInStatus<span class="token punctuation">.</span>Success<span class="token punctuation">,</span> ticket<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>In the code above, we have defined some interesting things:</p><ol><li>We have created an enumeration <code>CheckInStatus</code> to set the attendee&rsquo;s check-in status.</li><li>We also defined a record <code>CheckInResult</code>, which packages the check-in status together with the associated ticket information, to be able to display the correct information in the UI.</li><li>We defined the service class that will be injected into the Blazor components. The constructor receives the configuration with data such as the base URL for validation, so that scanning the QR code from a mobile device works. We also created three mock records to preload the UI with data.</li><li>We created an event of type <code>Action</code>, which will allow us to notify changes when we scan QR codes from the phone.</li><li>The method <code>IssueTicket</code> generates a sequential number safely thanks to the use of <code>Interlocked.Increment</code>, intended for scenarios where multiple objects may want to modify the same value at once.</li><li>The method <code>BuildValidationUrl</code> constructs a URL encoded in the QR code, combining the base URL plus the ticket number.</li><li>The method <code>CheckIn</code> is the one that performs ticket validation. It accepts a value and searches for a match either by code, barcode number or by validation URL. This will allow reading both the QR code and the barcode.</li></ol><p>With the service class ready, it must be registered in the next section.</p><h3 id="registering-the-ticket-service-in-the-blazor-app">Registering the Ticket Service in the Blazor App</h3><p>The next step will be to register the <code>TicketService</code> service as a singleton so it can be injected into components. We&rsquo;ll do this from <code>Program.cs</code> as follows:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">var</span> builder <span class="token operator">=</span> WebApplication<span class="token punctuation">.</span><span class="token function">CreateBuilder</span><span class="token punctuation">(</span>args<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
builder<span class="token punctuation">.</span>Services<span class="token punctuation">.</span><span class="token generic-method function">AddSingleton<span class="token punctuation">&lt;</span>TicketService<span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">var</span> app <span class="token operator">=</span> builder<span class="token punctuation">.</span><span class="token function">Build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><h3 id="creating-the-section-for-ticket-generation">Creating the Section for Ticket Generation</h3><p>We&rsquo;ll create a new component page called <code>EventTickets.razor</code>, starting by defining the route, the rendering mode and the injection of the service:</p><pre class=" language-xml"><code class="prism  language-xml">@page "/tickets"
@using TicketsSystemDemo.Services
@rendermode InteractiveServer
@inject TicketService TicketService

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>PageTitle</span><span class="token punctuation">&gt;</span></span>Event Ticketing Studio<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>PageTitle</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Event Ticketing Studio<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-muted mb-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Issue attendee tickets with a scannable QR code and a 1D barcode, then validate them at the gate.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>Once the main part of the app is defined, we&rsquo;ll create a first section that shows a form and serves to generate tickets. We can achieve this using Telerik components such as <code>TelerikTextBox</code>, <code>TelerikDropDownList</code> and <code>TelerikButton</code>, which allow simple configuration and implementation:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row g-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-lg-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm h-100<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-header fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>1. Issue a ticket<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Attendee name<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikTextBox</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>attendeeName<span class="token punctuation">"</span></span> <span class="token attr-name">Placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Jane Doe<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>

                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label mt-3<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Email<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikTextBox</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>email<span class="token punctuation">"</span></span> <span class="token attr-name">Placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>jane@contoso.com<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>

                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label mt-3<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Ticket type<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikDropDownList</span> <span class="token attr-name">Data</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ticketTypes<span class="token punctuation">"</span></span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ticketType<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>

                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikButton</span> <span class="token attr-name">OnClick</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>IssueTicket<span class="token punctuation">"</span></span>
                               <span class="token attr-name">ThemeColor</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@ThemeConstants.Button.ThemeColor.Primary<span class="token punctuation">"</span></span>
                               <span class="token attr-name">Icon</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@SvgIcon.Plus<span class="token punctuation">"</span></span>
                               <span class="token attr-name">Class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mt-4 w-100<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                    Generate ticket
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>TelerikButton</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

@code {
    private readonly List<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>string</span><span class="token punctuation">&gt;</span></span> ticketTypes = new() { "General Admission", "VIP", "Speaker" };

    private string attendeeName = string.Empty;
    private string email = string.Empty;
    private string ticketType = "General Admission";

    private Ticket? selectedTicket;

    private void IssueTicket()
    {
        if (string.IsNullOrWhiteSpace(attendeeName))
            return;

        selectedTicket = TicketService.IssueTicket(attendeeName, email, ticketType);

        attendeeName = string.Empty;
        email = string.Empty;
        ticketType = "General Admission";        
    }
}
</code></pre><p>The form will allow entering the attendee&rsquo;s name, email and ticket type. On the other hand, in the code section, the button event is handled to create a new ticket, using the service <code>TicketService</code>.</p><p>The result is as follows:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/blazor-ticket-issuance-form.gif?sfvrsn=2c639bae_2" alt="Ticket issuance form in Blazor application interface" /></p><h3 id="displaying-the-generated-qr-codes-and-barcodes">Displaying the Generated QR Codes and Barcodes</h3><p>The action of creating a ticket automatically creates a <code>Ticket</code>, which, as you&rsquo;ll recall, contains the information to display the QR codes and barcodes. To show them in the interface, simply use the <code>TelerikQRCode</code> component to display QR codes and <code>TelerikBarcode</code> to display barcodes, each of them bound to their corresponding property:</p><pre class=" language-xml"><code class="prism  language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row g-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-lg-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        ...
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-lg-8<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm h-100<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-header fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>2. Ticket preview<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                @if (selectedTicket is null)
                {
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-muted text-center py-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                        Issue a ticket or select one from the list to preview its codes.
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                }
                else
                {
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row align-items-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h4</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@selectedTicket.AttendeeName<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h4</span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-muted<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@selectedTicket.Email<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>badge bg-primary mt-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@selectedTicket.TicketType<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dl</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row mt-3 mb-0 small<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dt</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Code<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dt</span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-7<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@selectedTicket.Code<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dt</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Issued<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dt</span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-7<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@selectedTicket.IssuedAt.ToString("g")<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dt</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Status<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dt</span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dd</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-7<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                                    &lt;span class="badge @(selectedTicket.CheckedIn ? "bg-success" : "bg-secondary")"&gt;
                                        @(selectedTicket.CheckedIn ? "Checked in" : "Not used")
                                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dd</span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dl</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-4 text-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikQRCode</span> <span class="token attr-name">Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@TicketService.BuildValidationUrl(selectedTicket)<span class="token punctuation">"</span></span>
                                           <span class="token attr-name">Size</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>180px<span class="token punctuation">"</span></span>
                                           <span class="token attr-name">ErrorCorrection</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@QRCodeErrorCorrectionLevel.M<span class="token punctuation">"</span></span>
                                           <span class="token attr-name">Color</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>#1b1b3a<span class="token punctuation">"</span></span>
                                           <span class="token attr-name">Background</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>white<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>small text-muted mt-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Scan to validate<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-3 text-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikBarcode</span> <span class="token attr-name">Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@selectedTicket.BarcodeNumber.ToString()<span class="token punctuation">"</span></span>
                                            <span class="token attr-name">Type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@BarcodeType.Code128<span class="token punctuation">"</span></span>
                                            <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>180px<span class="token punctuation">"</span></span>
                                            <span class="token attr-name">Height</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>90px<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>small text-muted mt-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Gate barcode<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                }
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>In the previous section, <code>TelerikQRCode</code> receives in its <code>Value</code> parameter the validation URL that the service constructs, which will allow check-in once scanned. And <code>TelerikBarcode</code> receives in its <code>Value</code> parameter the ticket number. In both cases, the components take care of rendering the codes in the UI automatically.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/generate-qr-and-barcode-ticket.gif?sfvrsn=e2c7a49f_2" alt="User interface showing QR and barcode generation for ticket" /></p><p>In the image above, we can see how the code preview updates almost instantaneously when a ticket is generated.</p><h3 id="showing-generated-tickets">Showing Generated Tickets</h3><p>Something that could be very useful is displaying previously generated tickets. This can be used to see detailed information for each ticket, as well as the ticket&rsquo;s current status.</p><p>We can achieve this using a <code>TelerikGrid</code> component, which allows a fairly high level of customization:</p><pre class=" language-xml"><code class="prism  language-xml">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row g-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
  ...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row g-4 mt-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-lg-7<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm h-100<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-header fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>3. Issued tickets<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body p-0<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikGrid</span> <span class="token attr-name">@ref</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ticketGrid<span class="token punctuation">"</span></span>
                             <span class="token attr-name">Data</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@TicketService.Tickets<span class="token punctuation">"</span></span>
                             <span class="token attr-name">OnRowClick</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@OnTicketRowClick<span class="token punctuation">"</span></span>
                             <span class="token attr-name">Sortable</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>true<span class="token punctuation">"</span></span>
                             <span class="token attr-name">Height</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>360px<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>GridColumns</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>GridColumn</span> <span class="token attr-name">Field</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@nameof(Ticket.Code)<span class="token punctuation">"</span></span> <span class="token attr-name">Title</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Code<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>160px<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>GridColumn</span> <span class="token attr-name">Field</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@nameof(Ticket.AttendeeName)<span class="token punctuation">"</span></span> <span class="token attr-name">Title</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Attendee<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>GridColumn</span> <span class="token attr-name">Field</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@nameof(Ticket.TicketType)<span class="token punctuation">"</span></span> <span class="token attr-name">Title</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Type<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>150px<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>GridColumn</span> <span class="token attr-name">Field</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@nameof(Ticket.CheckedIn)<span class="token punctuation">"</span></span> <span class="token attr-name">Title</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>Status<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>130px<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Template</span><span class="token punctuation">&gt;</span></span>
                                @{
                                    var ticket = (Ticket)context;
                                }
                                &lt;span class="badge @(ticket.CheckedIn ? "bg-success" : "bg-secondary")"&gt;
                                    @(ticket.CheckedIn ? "Checked in" : "Not used")
                                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
                            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Template</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>GridColumn</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>GridColumns</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>TelerikGrid</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
...
@code {
  ...
  private TelerikGrid<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Ticket</span><span class="token punctuation">&gt;</span></span>? ticketGrid;
  ...
  private void OnTicketRowClick(GridRowClickEventArgs args)
  {
      selectedTicket = (Ticket)args.Item;
  }  
}
</code></pre><p>The above configuration allows binding to information obtained from the service, as well as updating the selected entry thanks to the <code>OnTicketRowClick</code> method. We also use <code>Template</code> to customize the view of the last column, indicating whether the ticket has been checked in or not.</p><p>The result of the implementation is as follows:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/telerikgrid-ticket-list.gif?sfvrsn=faa1aac5_2" alt="List of generated support tickets shown in TelerikGrid" /></p><p>Now, let&rsquo;s see how to check the status of a ticket.</p><h3 id="validating-access-to-the-event">Validating Access to the Event</h3><p>The last section we will implement will be a simulation so that people can validate the status of a ticket. The implementation is as follows:</p><pre class=" language-xml"><code class="prism  language-xml">...
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row g-4 mt-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-lg-7<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        ...
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-lg-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm h-100<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-header fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>4. Gate check-in<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-label<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Scanned value (code, barcode number or URL)<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikTextBox</span> <span class="token attr-name">@bind-Value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>scannedValue<span class="token punctuation">"</span></span> <span class="token attr-name">Placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>TKT-2026-001001<span class="token punctuation">"</span></span> <span class="token attr-name">Width</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>100%<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>

                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>TelerikButton</span> <span class="token attr-name">OnClick</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>ValidateTicket<span class="token punctuation">"</span></span>
                               <span class="token attr-name">ThemeColor</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@ThemeConstants.Button.ThemeColor.Success<span class="token punctuation">"</span></span>
                               <span class="token attr-name">Icon</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>@SvgIcon.Check<span class="token punctuation">"</span></span>
                               <span class="token attr-name">Class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mt-3 w-100<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                    Validate ticket
                <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>TelerikButton</span><span class="token punctuation">&gt;</span></span>

                @if (checkInResult is not null)
                {
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>alert @GetAlertClass() mt-3 mb-0<span class="token punctuation">"</span></span> <span class="token attr-name">role</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>alert<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                        @GetResultMessage()
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                }
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
@code {
    ...
    private string scannedValue = string.Empty;
    private CheckInResult? checkInResult;
    ...
    private void ValidateTicket()
    {
        if (string.IsNullOrWhiteSpace(scannedValue))
            return;

        checkInResult = TicketService.CheckIn(scannedValue);

        if (checkInResult.Ticket is not null)
            selectedTicket = checkInResult.Ticket;

        ticketGrid?.Rebind();
    }

    private string GetAlertClass() =&gt; checkInResult!.Status switch
    {
        CheckInStatus.Success =&gt; "alert-success",
        CheckInStatus.AlreadyCheckedIn =&gt; "alert-warning",
        _ =&gt; "alert-danger"
    };

    private string GetResultMessage() =&gt; checkInResult!.Status switch
    {
        CheckInStatus.Success =&gt; $"Welcome, {checkInResult.Ticket!.AttendeeName}! Ticket accepted.",
        CheckInStatus.AlreadyCheckedIn =&gt; $"Ticket already used at {checkInResult.Ticket!.CheckedInAt:t}.",
        _ =&gt; "Invalid ticket. No match found."
    };
}
</code></pre><p>In the previous code, we created a button to validate the ticket based on the scanned information. Depending on the result, an appropriate color or message will be displayed.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/validation-simulator-section.gif?sfvrsn=5ba5ba86_2" alt="Simulator section showing ticket validation statuses" /></p><p>Finally, let&rsquo;s see how we can test the application using our physical device.</p><h3 id="creating-the-validation-page-for-the-qr-code">Creating the Validation Page for the QR Code</h3><p>Although in the previous section it&rsquo;s already possible to do check-in using either of the two values in character format, ideally we want to use the phone&rsquo;s camera or a similar device.</p><p>To achieve this, we&rsquo;re going to create a page that receives the code in the route and performs the check-in as soon as it opens. We&rsquo;ll do this by creating the <code>Validate.razor</code> component:</p><pre class=" language-xml"><code class="prism  language-xml">@page "/validate/{Code}"
@using TicketsSystemDemo.Services
@rendermode InteractiveServer
@inject TicketService TicketService

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>PageTitle</span><span class="token punctuation">&gt;</span></span>Ticket validation<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>PageTitle</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row justify-content-center mt-4<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>col-md-6<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card shadow-sm<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-header fw-semibold<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Gate validation<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card-body text-center py-5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                @if (result is null)
                {
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-muted<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>Validating ticket <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>strong</span><span class="token punctuation">&gt;</span></span>@Code<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>strong</span><span class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                }
                else
                {
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>alert @GetAlertClass() mb-4<span class="token punctuation">"</span></span> <span class="token attr-name">role</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>alert<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h4</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@GetTitle()<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h4</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>@GetResultMessage()<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

                    @if (result.Ticket is not null)
                    {
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h5</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>mb-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@result.Ticket.AttendeeName<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h5</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>badge bg-primary<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@result.Ticket.TicketType<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
                        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>small text-muted mt-2<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>@result.Ticket.Code<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
                    }
                }
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>

@code {
    [Parameter]
    public string Code { get; set; } = string.Empty;

    private CheckInResult? result;

    protected override void OnInitialized()
    {        
        if (RendererInfo.IsInteractive)
            result = TicketService.CheckIn(Code);
    }

    private string GetAlertClass() =&gt; result!.Status switch
    {
        CheckInStatus.Success =&gt; "alert-success",
        CheckInStatus.AlreadyCheckedIn =&gt; "alert-warning",
        _ =&gt; "alert-danger"
    };

    private string GetTitle() =&gt; result!.Status switch
    {
        CheckInStatus.Success =&gt; "Access granted",
        CheckInStatus.AlreadyCheckedIn =&gt; "Ticket already used",
        _ =&gt; "Invalid ticket"
    };

    private string GetResultMessage() =&gt; result!.Status switch
    {
        CheckInStatus.Success =&gt; $"Welcome, {result.Ticket!.AttendeeName}! Ticket accepted.",
        CheckInStatus.AlreadyCheckedIn =&gt; $"This ticket was already used at {result.Ticket!.CheckedInAt:t}.",
        _ =&gt; "No matching ticket was found for this code."
    };
}
</code></pre><p>In the previous code, we receive the code to validate thanks to the <code>Code</code> parameter. Likewise, <code>RendererInfo.IsInteractive</code> is checked before calling <code>CheckIn</code>. We do this to prevent the check-in from executing twice, due to Blazor&rsquo;s prerendering.</p><h3 id="testing-the-qr-code-using-a-dev-tunnel">Testing the QR Code Using a Dev Tunnel</h3><p>When developing an app, we regularly use <code>localhost</code> to test the site, which means a mobile device won&rsquo;t be able to reach the same development URL to perform check-in from the phone.</p><p>To solve the problem, we must somehow expose the app at a public URL. Although there are many ways to do this, I will use a dev tunnel, which is a free method provided by VS 2026 to achieve it easily.</p><p>A dev tunnel is a secure tunnel that creates a public URL while the app is running, forwarding requests that arrive at it to your local server. In VS 2026, you can create it from the <strong>View</strong> | <strong>Other Windows</strong> | <strong>Dev Tunnels</strong> menu.</p><p>We can created one with the following configuration:</p><ul><li>Name: eventticketing</li><li>Tunnel Type: Persistent (to keep the same URL)</li><li>Access: Public</li></ul><p>After creating it, we must select it before running the application:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/selecting-dev-tunnel-ui.png?sfvrsn=3901fff_2" alt="Developer tunnel option in VS 2026" /></p><p>When we start the application, we will be given a tunnel like this:</p><pre class=" language-text"><code class="prism  language-text">https://mcbx4kgd-7121.usw3.devtunnels.ms
</code></pre><p>So that the QR code points to that tunnel instead of the fictitious domain, let&rsquo;s modify the file <code>appsettings.Development.json</code>, adding the key in the file:</p><pre class=" language-json"><code class="prism  language-json"><span class="token punctuation">{</span>
  <span class="token operator">...</span>
  <span class="token string">"Tickets"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token string">"ValidationBaseUrl"</span><span class="token punctuation">:</span> <span class="token string">"https://mcbx4kgd-7121.usw3.devtunnels.ms/validate"</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>With the above, while we are in development mode we will use the tunnel URL, while in production the URL defined in the service will be used.</p><p>Finally, in <code>EventTickets.razor</code> we will subscribe to the <code>TicketsChanged</code> event to refresh the status of the ticket scanned by QR:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
@implements <span class="token class-name">IDisposable</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
@code <span class="token punctuation">{</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token keyword">protected</span> <span class="token keyword">override</span> <span class="token keyword">void</span> <span class="token function">OnInitialized</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        TicketService<span class="token punctuation">.</span>TicketsChanged <span class="token operator">+</span><span class="token operator">=</span> OnTicketsChanged<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">private</span> <span class="token keyword">async</span> <span class="token keyword">void</span> <span class="token function">OnTicketsChanged</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">await</span> <span class="token function">InvokeAsync</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
        <span class="token punctuation">{</span>
            ticketGrid<span class="token operator">?</span><span class="token punctuation">.</span><span class="token function">Rebind</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token function">StateHasChanged</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">Dispose</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        TicketService<span class="token punctuation">.</span>TicketsChanged <span class="token operator">-</span><span class="token operator">=</span> OnTicketsChanged<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span>
</code></pre><p>When testing the application, the following happens:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/qr-code-reading-demo.gif?sfvrsn=b6a14b4d_2" alt="Scanning QR code with smartphone camera" /></p><p>In the video above, you can see how the grid starts with all tickets in an unused state. Then, we scan the QR code, which takes us to the validation page that checks the ticket&rsquo;s validity. Finally, when returning to the home page, we see the grid with the updated ticket.</p><h2 id="conclusion">Conclusion</h2><p>Throughout this article, you have been able to see a real-world scenario of using the Blazor QR Code and Blazor Barcode components, which greatly simplify the task when we need to implement these types of codes in our applications.</p><p>You have learned about the model used, the service, different parts of an application that involve these kinds of apps, and even a possible implementation of QR code reading while developing the application.</p><p>It&rsquo;s your turn to create solutions faster using these components in your clients&rsquo; apps.</p><p><a target="_blank" href="https://www.telerik.com/try/ui-for-blazor" class="Btn">Try Telerik UI for Blazor</a></p><img src="https://feeds.telerik.com/link/10827/17521717.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:b5658cbf-cc41-48d3-812c-7f9f9fb4a55b</id>
    <title type="text">Introducing Server Components in TanStack Start</title>
    <summary type="text">This simple app shows how React Server Components work in TanStack Start, how server and client components compose together, and what this means for performance and application design.</summary>
    <published>2026-11-10T18:08:35Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Christian Nwamba </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17521718/introducing-server-components-tanstack-start"/>
    <content type="text"><![CDATA[<p><span class="featured">This simple app shows how React Server Components work in TanStack Start, how server and client components compose together, and what this means for performance and application design.</span></p><p>Modern web applications have always faced a trade-off. Ship more JavaScript to the browser, and you get rich interactivity, but at the cost of larger bundles and slower pages. Ship less JavaScript, and performance improves at the cost of user experience.</p><p><a target="_blank" href="https://react.dev/reference/rsc/server-components">React Server Components</a> (RSCs) aim to fix this trade-off by keeping server-only code on the server instead of sending it to the client. The result is smaller bundles and less JavaScript for the browser to download. This also means a different way of building <a target="_blank" href="https://react.dev/">React</a> applications.</p><p><a target="_blank" href="https://tanstack.com/start/latest">TanStack Start</a> is one of the first frameworks outside of <a target="_blank" href="https://nextjs.org/">Next.js</a> to adopt RSC. Although it is still experimental, it&rsquo;s stable enough to explore the architecture in practice.</p><p>In this post, we&rsquo;ll build a simple blog reader to see how React Server Components work in TanStack Start, how server and client components compose together, and what this means for performance and application design.</p><h2 id="prerequisites">Prerequisites</h2><p>To get the most out of this article, it is assumed that you have:</p><ul><li>A basic understanding of the React library</li><li>Comfortability with <a target="_blank" href="https://www.typescriptlang.org/">TypeScript</a></li><li><a target="_blank" href="http://node.js">Node.js</a> installed</li></ul><h2 id="react-server-components">React Server Components</h2><p>What are React Server Components? RSCs are components that render on the server, and only the rendered output gets sent to the browser. None of the component code (imports, logic, dependencies) reaches the browser. In a nutshell, the browser just gets a finished product, which in this case is rendered content.</p><p>This is different from the normal React components we&rsquo;re used to. In a normal React component, when you import a library at the top of your file, that library gets bundled and shipped to the browser. Every user who visits your page has to download it.</p><p>For instance, the Markdown parser we&rsquo;ll be using in this article converts Markdown format to HTML. The user never needs to interact with it directly, but if it&rsquo;s one of your imports, it gets added to everything the browser has to download.</p><p>With a server component, that import stays on the server. You can use a library of maybe 500kB, and none of it reaches the browser. The server does the parsing and sends the browser the finished HTML. This way, the user&rsquo;s device does less work.</p><p>Server components are also async by default. This means you can await database queries, API calls or any async operation directly inside the component without <code>useEffect</code>. The component just waits for the data and renders it. The constraint is that server components can&rsquo;t have interactivity. Server components are for the static, data-heavy parts of your UI. Interactivity lives in client components. The two can work together through composition, which we&rsquo;ll look at further down in the article.</p><h2 id="rsc-ssr-and-server-functions">RSC, SSR and Server Functions</h2><p>We&rsquo;ve already looked at RSC and what it entails, but there are major misconceptions around three concepts that are often confused: RSC, server-side rendering (SSR) and server functions.</p><p>With SSR, instead of waiting for the browser to execute your JavaScript, the server renders the page first and sends back HTML that&rsquo;s already populated with content (hence &ldquo;server-side rendering&rdquo;). That means users can start reading the content on the page almost immediately.</p><p>There&rsquo;s still one important thing to understand, though. SSR doesn&rsquo;t stop your React code from being sent to the browser. After the HTML arrives, the browser downloads your JavaScript, runs your components again and tries to wire up all the event handlers so the page becomes interactive. That second step is known as hydration. This means your components render twice. First on the server to produce the initial HTML, and then in the browser to make that HTML interactive. SSR solves the problem of slow initial rendering, but it doesn&rsquo;t reduce the amount of JavaScript the browser still has to download.</p><p>RSC goes further. Server components render on the server, and their code never reaches the browser. There is no hydration because there is no client code to hydrate. The server renders and sends the output. The difference from SSR is that SSR sends HTML and then reruns your component on the client. RSC sends the rendered output and never reruns the component on the client, because the component code never went there.</p><p>Server functions are different from both. A server function isn&rsquo;t a component at all. It is a function that runs on the server and returns data. You call it from the client, it executes on the server and it sends back a result.</p><p>In TanStack Start, server functions and RSC work together. You render a server component inside a server function handler and return the rendered output through a loader. The server function runs the server component and delivers its output to the route.</p><p>With that out of the way, let&rsquo;s set up our project and see React Server Components in action.</p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">Learn more about RSC and SSR</h4></div><div class="col-8"><p class="u-fs16 u-mb0">Get a clear understanding of what these terms mean and how they relate: React Server Components (RSCs), Client-Side Rendering (CSR) and Server-Side Rendering (SSR). Read <a target="_blank" href="https://www.telerik.com/blogs/rsc-ssr-csr-omg">RSC, SSR and CSR&mdash;OMG!</a>.</p></div></div><hr class="u-mb3" /></aside><h2 id="project-setup">Project Setup</h2><p>In this article, we will build a blog post reader. The app will have a list of posts where the content is written in Markdown. A Markdown parser will convert that content to HTML on the server, meaning the parser never ships to the browser. Later on, we&rsquo;ll see how we can add interactivity to these server components with the help of RSC composition.</p><p>Here is a GIF representation of the app we&rsquo;ll be building.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/blog-reader.gif?sfvrsn=394700cb_2" title="Blog reader with server component in Tanstack" alt="Blog reader with server component in Tanstack" /></p><p>Let&rsquo;s scaffold a new TanStack Start project by running the following command in the terminal:</p><pre class=" language-shell"><code class="prism  language-shell">npx @tanstack/cli create tanstack-rsc-blog -y
</code></pre><p>Navigate into the project and install dependencies:</p><pre class=" language-shell"><code class="prism  language-shell">cd tanstack-rsc-blog
npm install
</code></pre><p>RSC isn&rsquo;t enabled by default in a TanStack Start project. We need to bring in an extra Vite plugin that tells Vite how to split the bundle correctly, keeping server component code on the server and only sending client code to the browser.</p><pre class=" language-shell"><code class="prism  language-shell"> npm install -D @vitejs/plugin-rsc
</code></pre><p>Now open your <code>vite.config.ts</code> file and update it to enable RSC:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> defineConfig <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vite'</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> devtools <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@tanstack/devtools-vite'</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> tanstackStart <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@tanstack/react-start/plugin/vite'</span>
<span class="token keyword">import</span> viteReact <span class="token keyword">from</span> <span class="token string">'@vitejs/plugin-react'</span>
<span class="token keyword">import</span> tailwindcss <span class="token keyword">from</span> <span class="token string">'@tailwindcss/vite'</span>
<span class="token keyword">import</span> rsc <span class="token keyword">from</span> <span class="token string">'@vitejs/plugin-rsc'</span>

<span class="token keyword">const</span> config <span class="token operator">=</span> <span class="token function">defineConfig</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  resolve<span class="token punctuation">:</span> <span class="token punctuation">{</span> tsconfigPaths<span class="token punctuation">:</span> <span class="token keyword">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span>
    <span class="token function">devtools</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">tailwindcss</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">tanstackStart</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      rsc<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        enabled<span class="token punctuation">:</span> <span class="token keyword">true</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">rsc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token function">viteReact</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> config
</code></pre><p>Two things changed from the default config: we added <code>import rsc from '@vitejs/plugin-rsc'</code> and passed <code>rsc: { enabled: true }</code> to <code>tanstackStart</code>. Without both of these, <code>createCompositeComponent</code> will not work.</p><p>Finally, start the dev server to confirm everything is working:</p><pre class=" language-shell"><code class="prism  language-shell">npm run dev
</code></pre><p>If you see the default TanStack page in your browser, you&rsquo;re good to go.</p><h2 id="defining-the-data">Defining the Data</h2><p>Before we build any components, we need data to work with. In production, this might come from a database, but to keep the focus on RSC, we&rsquo;ll use a hardcoded array of posts.</p><p>Create a <code>src/data/posts.ts</code> file, and add the following to it:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">export</span> <span class="token keyword">type</span> Post <span class="token operator">=</span> <span class="token punctuation">{</span>
  id<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  title<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  author<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  date<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  content<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> posts<span class="token punctuation">:</span> Post<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>
  <span class="token punctuation">{</span>
    id<span class="token punctuation">:</span> <span class="token string">"1"</span><span class="token punctuation">,</span>
    title<span class="token punctuation">:</span> <span class="token string">"Getting Started with TanStack Start"</span><span class="token punctuation">,</span>
    author<span class="token punctuation">:</span> <span class="token string">"John Doe"</span><span class="token punctuation">,</span>
    date<span class="token punctuation">:</span> <span class="token string">"May 20, 2025"</span><span class="token punctuation">,</span>
    content<span class="token punctuation">:</span> <span class="token template-string"><span class="token string">`
# Getting Started with TanStack Start

TanStack Start is a **full-stack React framework** built on TanStack Router.

## What it gives you

- Server-side rendering out of the box
- Type-safe routing
- Server functions with \`createServerFn\`
- React Server Components

## Why it matters

Instead of maintaining a separate API, you write server functions and call them directly from your components. No fetch calls, no API routes, just functions.
    `</span></span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    id<span class="token punctuation">:</span> <span class="token string">"2"</span><span class="token punctuation">,</span>
    title<span class="token punctuation">:</span> <span class="token string">"Understanding React Server Components"</span><span class="token punctuation">,</span>
    author<span class="token punctuation">:</span> <span class="token string">"John Doe"</span><span class="token punctuation">,</span>
    date<span class="token punctuation">:</span> <span class="token string">"May 20, 2025"</span><span class="token punctuation">,</span>
    content<span class="token punctuation">:</span> <span class="token template-string"><span class="token string">`
# Understanding React Server Components

Server Components render on the **server only**. The component code never reaches the browser.

## The key difference from SSR

With SSR, component code still ships to the browser for hydration. With RSC, it never does.

## When to use them

- Heavy dependencies that should not ship to the browser
- Static content that does not need interactivity
- Secure logic that should never reach the client
    `</span></span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>
</code></pre><p>We just have a standard type definition and hardcoded data here. The important detail is that the <code>content</code> field is raw Markdown, not HTML. The conversion from Markdown to HTML happens inside the server component, which we&rsquo;ll see when we build it next.</p><h2 id="building-the-postcard-server-component">Building the PostCard Server Component</h2><p>This is where we&rsquo;ll start seeing RSC in practice. Before anything, we need to install a Markdown parser that converts a Markdown string into HTML that can be rendered by our component.</p><pre class=" language-shell"><code class="prism  language-shell">npm install marked
</code></pre><p>Create a <code>src/components/PostCard.tsx</code> file and add the following to it:</p><pre class=" language-jsx"><code class="prism  language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> marked <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"marked"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> createCompositeComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-start/rsc"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> type <span class="token punctuation">{</span> Post <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../data/posts"</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">createPostCard</span><span class="token punctuation">(</span>post<span class="token punctuation">:</span> Post<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> contentHtml <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">marked</span><span class="token punctuation">(</span>post<span class="token punctuation">.</span>content<span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token function">createCompositeComponent</span><span class="token punctuation">(</span>
    <span class="token punctuation">(</span>props<span class="token punctuation">:</span> <span class="token punctuation">{</span> renderLikeButton<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> React<span class="token punctuation">.</span>ReactNode <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>article</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>card rounded-xl p-7 space-y-4 hover:shadow-[var(--shadow-md)] transition-shadow<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>space-y-1.5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-2xl font-extrabold text-[var(--ink)] leading-tight tracking-tight<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token punctuation">{</span>post<span class="token punctuation">.</span>title<span class="token punctuation">}</span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>flex items-center gap-2 text-sm text-[var(--ink-soft)]<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>font-medium<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token punctuation">{</span>post<span class="token punctuation">.</span>author<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>w-1 h-1 rounded-full bg-[var(--ink-soft)] opacity-40<span class="token punctuation">"</span></span> <span class="token punctuation">/&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">{</span>post<span class="token punctuation">.</span>date<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span>
          <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>prose-content<span class="token punctuation">"</span></span>
          <span class="token attr-name">dangerouslySetInnerHTML</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> __html<span class="token punctuation">:</span> contentHtml <span class="token punctuation">}</span><span class="token punctuation">}</span></span>
        <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>pt-4 border-t border-[var(--line)] flex items-center<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token punctuation">{</span>props<span class="token punctuation">.</span>renderLikeButton<span class="token operator">?</span><span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>article</span><span class="token punctuation">&gt;</span></span>
    <span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>In the code above, we used <code>createCompositeComponent</code> instead of <code>renderServerComponent</code> because this component needs a place where a client component can be inserted. <code>renderServerComponent</code> comes in handy when you only need server-rendered output, while <code>createCompositeComponent</code> lets us expose slots that client components can later fill.</p><p>We also import <code>marked</code> to convert each post&rsquo;s Markdown into HTML. Since this code runs on the server, <code>marked</code> is never shipped to the client bundle. Inside <code>createPostCard</code>, we parse the Markdown and render the post layout. You&rsquo;ll also notice <code>renderLikeButton</code> in the component props. We&rsquo;ve also made it optional so the component can still render if nothing is passed.</p><p>Finally, we call <code>props.renderLikeButton?.()</code> where we want the interactive Like button to appear. We&rsquo;ll build that button next. It will have <code>useState</code>, click handlers, and all the client-side interactivity that server components can&rsquo;t provide. Think of this as leaving an empty spot where a client component with interactivity can come and live. Further down, when we render this component with <code>CompositeComponent</code>, we&rsquo;ll pass the function that fills this slot.</p><h2 id="client-component">Client Component</h2><p>Now we need interactivity. Server components can&rsquo;t handle click events, state, or any client-side behavior, as we mentioned earlier. We need a client component for this.</p><p>Create a <code>src/components/LikeButton.tsx</code> file and add the following to it:</p><pre class=" language-jsx"><code class="prism  language-jsx"><span class="token string">"use client"</span><span class="token punctuation">;</span>

<span class="token keyword">import</span> <span class="token punctuation">{</span> useState <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"react"</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">LikeButton</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>count<span class="token punctuation">,</span> setCount<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>liked<span class="token punctuation">,</span> setLiked<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">const</span> <span class="token function-variable function">handleClick</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>liked<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token function">setCount</span><span class="token punctuation">(</span>count <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token function">setLiked</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
      <span class="token function">setCount</span><span class="token punctuation">(</span>count <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token function">setLiked</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token operator">&lt;</span>button
      onClick<span class="token operator">=</span><span class="token punctuation">{</span>handleClick<span class="token punctuation">}</span>
      className<span class="token operator">=</span><span class="token punctuation">{</span><span class="token template-string"><span class="token string">`inline-flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm font-semibold transition-all select-none </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>
        liked
          <span class="token operator">?</span> <span class="token string">"bg-[var(--like-heart)] text-white shadow-md"</span>
          <span class="token punctuation">:</span> <span class="token string">"bg-[var(--surface)] text-[var(--ink-soft)] border border-[var(--line)] hover:border-[var(--accent)] hover:text-[var(--accent)] hover:shadow-sm active:scale-95"</span>
      <span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">`</span></span><span class="token punctuation">}</span>
    <span class="token operator">&gt;</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span> <span class="token attr-name">className</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>liked <span class="token operator">?</span> <span class="token string">"scale-110"</span> <span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">}</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token punctuation">{</span>liked <span class="token operator">?</span> <span class="token string">"❤️"</span> <span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">}</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">{</span>count<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>span</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">&gt;</span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The <code>"use client"</code> directive tells React that this component should run on the client. It handles the interactivity, <code>useState</code> and event handlers, and this code ships to the browser. Basically, this component just tracks likes and toggles between liked and unliked states, and the button style changes based on the state.</p><h2 id="building-the-homepage">Building the Homepage</h2><p>What we do now is bring everything into the route. Open <code>src/routes/index.tsx</code> and replace the default code with:</p><pre class=" language-jsx"><code class="prism  language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> createServerFn <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-start"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> CompositeComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-start/rsc"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> posts <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../data/posts"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> createPostCard <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../components/PostCard"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> LikeButton <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../components/LikeButton"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> createFileRoute <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-router"</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> getPosts <span class="token operator">=</span> <span class="token function">createServerFn</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">handler</span><span class="token punctuation">(</span><span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> renderedPosts <span class="token operator">=</span> <span class="token keyword">await</span> Promise<span class="token punctuation">.</span><span class="token function">all</span><span class="token punctuation">(</span>
    posts<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token keyword">async</span> <span class="token punctuation">(</span>post<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> src <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">createPostCard</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span> id<span class="token punctuation">:</span> post<span class="token punctuation">.</span>id<span class="token punctuation">,</span> src <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> <span class="token punctuation">{</span> renderedPosts <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> Route <span class="token operator">=</span> <span class="token function">createFileRoute</span><span class="token punctuation">(</span><span class="token string">"/"</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  loader<span class="token punctuation">:</span> <span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">await</span> <span class="token function">getPosts</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  component<span class="token punctuation">:</span> HomePage<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">HomePage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">{</span> renderedPosts <span class="token punctuation">}</span> <span class="token operator">=</span> Route<span class="token punctuation">.</span><span class="token function">useLoaderData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>max-w-2xl mx-auto px-4 py-10 sm:px-6 sm:py-14 space-y-8<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>space-y-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>kicker mb-1<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>The Blog<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-4xl font-extrabold tracking-tight text-[var(--ink)] sm:text-5xl<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          Latest Posts
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h1</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-base text-[var(--ink-soft)]<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          Thoughts<span class="token punctuation">,</span> notes<span class="token punctuation">,</span> and explorations<span class="token punctuation">.</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token punctuation">{</span>renderedPosts<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>post<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CompositeComponent</span>
            <span class="token attr-name">src</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>post<span class="token punctuation">.</span>src<span class="token punctuation">}</span></span>
            <span class="token attr-name">renderLikeButton</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>LikeButton</span> <span class="token punctuation">/&gt;</span></span><span class="token punctuation">}</span></span>
          <span class="token punctuation">/&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>In the code above, two pieces are working together here that are worth understanding: <code>createCompositeComponent</code> and <code>CompositeComponent</code>. They might look similar, but each has a different job. <code>createCompositeComponent</code> runs on the server. This is where we define the server-rendered layout and decide where interactive client components can be inserted. Those slots, or insertion points, are simply props that return JSX. In our case, we created one called <code>renderLikeButton</code>.</p><p><code>CompositeComponent</code>, on the other hand, runs on the client. It receives the serialized server output through the <code>src</code> prop and fills any slots we defined on the server. When we pass <code>renderLikeButton={() =&gt; &lt;LikeButton /&gt;}</code>, TanStack calls that function and inserts the returned JSX into the matching slot.</p><p>A good way to think about it is this: <code>createCompositeComponent</code> creates the blueprint on the server, while <code>CompositeComponent</code> assembles it on the client by filling in the interactive pieces. They never run in the same environment, but they work together to produce a single UI.</p><p>Now, run the dev server:</p><pre class=" language-shell"><code class="prism  language-shell">npm run dev
</code></pre><p>If you followed along correctly, you should see the blog page like the one below.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/server-rendered-posts.gif?sfvrsn=8820ff25_2" title="Server-rendered posts and interactive likes" alt="Server-rendered posts and interactive likes" /></p><h2 id="dynamic-routes">Dynamic Routes</h2><p>Currently, all our posts are on the homepage, which works fine, but we want each post to have its own URL. We&rsquo;ll achieve that by building a detail page for each post in this section.</p><p>Create a <code>src/routes/posts.$id.tsx</code> file and add the following to it:</p><pre class=" language-jsx"><code class="prism  language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> createFileRoute<span class="token punctuation">,</span> Link <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-router"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> createServerFn <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-start"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> CompositeComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-start/rsc"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> posts <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../data/posts"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> createPostCard <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../components/PostCard"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> LikeButton <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"../components/LikeButton"</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> getPost <span class="token operator">=</span> <span class="token function">createServerFn</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">validator</span><span class="token punctuation">(</span><span class="token punctuation">(</span>data<span class="token punctuation">:</span> unknown<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> data <span class="token operator">!==</span> <span class="token string">"object"</span> <span class="token operator">||</span> data <span class="token operator">===</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span><span class="token string">"Invalid"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token punctuation">(</span><span class="token string">"id"</span> <span class="token keyword">in</span> data<span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token keyword">typeof</span> data<span class="token punctuation">.</span>id <span class="token operator">!==</span> <span class="token string">"string"</span><span class="token punctuation">)</span>
      <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span><span class="token string">"ID required"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> data <span class="token keyword">as</span> <span class="token punctuation">{</span> id<span class="token punctuation">:</span> string <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">.</span><span class="token function">handler</span><span class="token punctuation">(</span><span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token punctuation">{</span> data <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> post <span class="token operator">=</span> posts<span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> p<span class="token punctuation">.</span>id <span class="token operator">===</span> data<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>post<span class="token punctuation">)</span> <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span><span class="token string">"Post not found"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">const</span> src <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">createPostCard</span><span class="token punctuation">(</span>post<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span> src <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> Route <span class="token operator">=</span> <span class="token function">createFileRoute</span><span class="token punctuation">(</span><span class="token string">"/posts/$id"</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  loader<span class="token punctuation">:</span> <span class="token keyword">async</span> <span class="token punctuation">(</span><span class="token punctuation">{</span> params <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">await</span> <span class="token function">getPost</span><span class="token punctuation">(</span><span class="token punctuation">{</span> data<span class="token punctuation">:</span> <span class="token punctuation">{</span> id<span class="token punctuation">:</span> params<span class="token punctuation">.</span>id <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  component<span class="token punctuation">:</span> PostPage<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">PostPage</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token punctuation">{</span> src <span class="token punctuation">}</span> <span class="token operator">=</span> Route<span class="token punctuation">.</span><span class="token function">useLoaderData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>max-w-2xl mx-auto p-8 space-y-6<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Link</span> <span class="token attr-name">to</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/<span class="token punctuation">"</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-[var(--accent)] hover:underline text-sm font-medium<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
        &larr; Back to posts
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Link</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>CompositeComponent</span> <span class="token attr-name">src</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span>src<span class="token punctuation">}</span></span> <span class="token attr-name">renderLikeButton</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>LikeButton</span> <span class="token punctuation">/&gt;</span></span><span class="token punctuation">}</span></span> <span class="token punctuation">/&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The overall pattern here is the same as what we did on the index route. The only difference is the validator and handler inside the server function. Instead of returning everything, we select the post we want based on the <code>id</code> and build a card for it. The validator checks that the <code>id</code> is actually a string. The handler either finds the post or throws an error. The route captures the specific <code>id</code> from the URL using <code>$id</code> in the file name. The loader passes that <code>id</code> to the server function, and the component renders the result.</p><h2 id="linking-to-posts">Linking to Posts</h2><p>We need a way to navigate to the detail page for each post. Open your <code>src/components/PostCard.tsx</code> file and wrap the post title with the <code>Link</code> component:</p><pre class=" language-jsx"><code class="prism  language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> Link <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@tanstack/react-router"</span><span class="token punctuation">;</span>


<span class="token keyword">export</span> <span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">createPostCard</span><span class="token punctuation">(</span>post<span class="token punctuation">:</span> Post<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> contentHtml <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">marked</span><span class="token punctuation">(</span>post<span class="token punctuation">.</span>content<span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token function">createCompositeComponent</span><span class="token punctuation">(</span>
    <span class="token punctuation">(</span>props<span class="token punctuation">:</span> <span class="token punctuation">{</span> renderLikeButton<span class="token operator">?</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> React<span class="token punctuation">.</span>ReactNode <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>article</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>space-y-1.5<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Link</span>
            <span class="token attr-name">to</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>/posts/$id<span class="token punctuation">"</span></span>
            <span class="token attr-name">params</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> id<span class="token punctuation">:</span> post<span class="token punctuation">.</span>id <span class="token punctuation">}</span><span class="token punctuation">}</span></span>
            <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>hover:underline<span class="token punctuation">"</span></span>
          <span class="token punctuation">&gt;</span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h2</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text-2xl font-extrabold text-[var(--ink)] leading-tight tracking-tight<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span>
              <span class="token punctuation">{</span>post<span class="token punctuation">.</span>title<span class="token punctuation">}</span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h2</span><span class="token punctuation">&gt;</span></span>
          <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Link</span><span class="token punctuation">&gt;</span></span>
          <span class="token punctuation">{</span><span class="token comment">/* rest of the component */</span><span class="token punctuation">}</span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>article</span><span class="token punctuation">&gt;</span></span>
    <span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The <code>Link</code> component works on both the server and the client. Here, it uses the <code>$id</code> parameter from the route to generate the correct URL.</p><p>Below is a preview of the dynamic route in action. Clicking a post title takes you to its dedicated detail page, and our Like button remains interactive.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/dynamic-routing-with-rsc.gif?sfvrsn=2c5fbc09_2" title="Dynamic routing with RSC" alt="Dynamic routing with RSC" /></p><h2 id="inspecting-the-production-build">Inspecting the Production Build</h2><p>One easy way to understand how React Server Components work is to inspect the production build. This lets us see what ends up on the server and what ends up on the client.</p><p>Run:</p><pre class=" language-shell"><code class="prism  language-shell">npm run build
</code></pre><p>We&rsquo;ll look at two parts of the output: the first is the server RSC build, and the second is the client build.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/server-rsc-build.png?sfvrsn=b839c22d_2" title="Server RSC build" alt="Server RSC build" /></p><p>Notice that <code>PostCard</code> appears in the server RSC build output. Since <code>PostCard</code> imports <code>marked</code>, that dependency never reaches the browser. It stays on the server and is never included in the client build.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/client-build.png?sfvrsn=3f19e2f7_2" title="Client build" alt="Client build" /></p><p>Looking at the client build, instead of shipping <code>PostCard</code> and the Markdown parsing logic, the browser only receives the code it needs for interactivity, such as <code>LikeButton</code> and <code>CompositeComponent</code>. The server has already done the heavy lifting of converting the Markdown to HTML. The browser doesn&rsquo;t need to download or execute <code>marked</code> at all.</p><h2 id="conclusion">Conclusion</h2><p>React Server Components change where your code runs, not just how your app looks. We built a simple blog reader and, along the way, saw how server components keep heavy dependencies off the client. In our case, the <code>marked</code> Markdown parser never made it into the client bundle. We also explored <code>createCompositeComponent</code> and saw how it lets you slot interactive client components into an otherwise server-rendered UI without giving up interactivity.</p><p>There&rsquo;s still a lot more to explore. The <a target="_blank" href="https://tanstack.com/blog/react-server-components#a-different-rsc-model">TanStack RSC</a> blog post and the official documentation are great places to continue from here.</p><hr /><blockquote><h3>Did You Know?</h3><p>One of the most robust <a href="https://www.telerik.com/kendo-react-ui/components/grid" target="_blank">React Grids</a> on the market comes with a native RSC mode! Learn more about it in this blog post:</p><br /><p><a href="https://www.telerik.com/blogs/introducing-rsc-mode-kendoreact-grid" target="_blank">Introducing RSC Mode in KendoReact Grid</a></p></blockquote><img src="https://feeds.telerik.com/link/10827/17521718.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:b529ad9a-e1c6-4dce-a834-9196763b772f</id>
    <title type="text">Object Calisthenics: 9 Exercises That Will Elevate Your Code Quality</title>
    <summary type="text">Object Calisthenics is a set of nine rules that challenges the way we think about and write object-oriented code. See how they can help evolve our code.</summary>
    <published>2026-11-05T20:03:18Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Assis Zang </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17516163/object-calisthenics-exercises-elevate-code-quality"/>
    <content type="text"><![CDATA[<p><span class="featured">Object Calisthenics is a set of nine rules that challenges the way we think about and write object-oriented code. See how they can help evolve our code.</span></p><p>Despite the rapid evolution of frameworks, a recurring problem persists in modern projects: object-oriented code featuring entities riddled with public properties, business logic scattered across services, duplicated validation logic and a domain model that fails to accurately represent the problem the system aims to solve. While this type of code may function, it tends to become increasingly difficult to evolve, test and maintain as the application grows.</p><p>It is in this context that Object Calisthenics remains relevant. Created as a set of exercises to foster better object-oriented programming habits, these rules are not meant to be followed rigidly. Instead, they exist to challenge how we model our objects and to encourage us to write code that is cohesive, expressive and characterized by well-defined responsibilities.</p><p>In this article, we will explore the nine rules proposed by Object Calisthenics, understand the rationale behind each one and analyze how they remain relevant for modern applications built with C# and ASP.NET Core.</p><h2 id="what-are-object-calisthenics">What Are Object Calisthenics?</h2><p>Object Calisthenics are a set of nine rules proposed by Jeff Bay and published originally in 2008 in the book <em>The ThoughtWorks Anthology</em>.</p><p>The term &ldquo;calisthenics&rdquo; refers to physical exercises, performed using one&rsquo;s own body weight to build strength, coordination and discipline. The idea behind Object Calisthenics follows this same philosophy: rather than teaching new language features, it proposes a series of constraints that encourage developers to practice better object-oriented modeling.</p><p>It is important to note that these rules should not be followed absolutely. They were created as an exercise to foster good design habits. By limiting certain practices such as the excessive use of long method chains between objects, developers are encouraged to reflect more deeply on each class&rsquo;s responsibilities and how objects collaborate. This can be compared to Test-Driven Development (TDD), which encourages programmers to start with tests but does not impose an absolute rule.</p><p>Although the rules were proposed many years ago, the problems they aim to solve persist in modern applications. We still encounter anemic domain models, classes with too many responsibilities and tight coupling between objects. Object Calisthenics offers a practical way to identify these issues and encourage solutions driven by behavior rather than data.</p><h2 id="getting-to-know-the-9-rules">Getting to Know the 9 Rules</h2><p>In the following sections, we will analyze each rule individually, understand its rationale and discuss how it can be applied or adapted in modern applications developed with C# and ASP.NET Core.</p><p>The nine rules are:</p><ol><li>One Level of Indentation Per Method</li><li>Don&rsquo;t Use the ELSE Keyword</li><li>Wrap All Primitives and Strings</li><li>First-Class Collections</li><li>One Dot Per Line</li><li>Don&rsquo;t Abbreviate</li><li>Keep All Entities Small</li><li>No Classes with More Than Two Instance Variables</li><li>No Getters/Setters/Properties</li></ol><p>All code examples covered in the post are available in this repository: <a target="_blank" href="https://github.com/zangassis/practicing-object-calisthenics">Practicing Object Calisthenics</a>.</p><h2 id="one-level-of-indentation-per-method">1. One Level of Indentation Per Method</h2><p>The first rule recommends that a method have only one level of indentation. Whenever we encounter multiple nested blocks (such as <code>if</code>, <code>foreach</code>, <code>while</code>, <code>try</code>, etc.), it usually indicates that the method is taking on too many responsibilities. Excessive indentation makes the execution flow harder to understand and increases complexity, making code maintenance more difficult.</p><p>Consider the following example of a service responsible for approving loan requests.</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">async</span> Task <span class="token function">ApproveAsync</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Status <span class="token operator">==</span> LoanStatus<span class="token punctuation">.</span>Pending<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>IsActive<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>CreditScore <span class="token operator">&gt;=</span> <span class="token number">700</span><span class="token punctuation">)</span>
      <span class="token punctuation">{</span>
        <span class="token keyword">var</span> debt <span class="token operator">=</span> <span class="token keyword">await</span> _debtRepository<span class="token punctuation">.</span><span class="token function">GetOutstandingDebtAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Id<span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token keyword">if</span> <span class="token punctuation">(</span>debt <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
          <span class="token punctuation">{</span>
            application<span class="token punctuation">.</span><span class="token function">Approve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token keyword">await</span> _loanRepository<span class="token punctuation">.</span><span class="token function">SaveAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token keyword">await</span> _notificationService<span class="token punctuation">.</span><span class="token function">SendApprovalEmailAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Email<span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Although the code works, the flow is buried within four levels of indentation. To understand what is happening, the reader must trace through all the conditional blocks to find the core logic, keeping track of the paths already traversed.</p><p>A more object-oriented approach is to delegate some decisions to smaller methods and use guard clauses to halt execution when a precondition is not met.</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">async</span> Task <span class="token function">ApproveAsync</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">var</span> canBeApproved <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">CanBeApproved</span><span class="token punctuation">(</span>application<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>canBeApproved<span class="token punctuation">)</span>
        <span class="token keyword">return</span><span class="token punctuation">;</span>

    <span class="token keyword">await</span> <span class="token function">ApproveLoan</span><span class="token punctuation">(</span>application<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">private</span> <span class="token keyword">async</span> Task<span class="token operator">&lt;</span><span class="token keyword">bool</span><span class="token operator">&gt;</span> <span class="token function">CanBeApproved</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span> 
<span class="token punctuation">{</span> 
    <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Status <span class="token operator">!=</span> LoanStatus<span class="token punctuation">.</span>Pending<span class="token punctuation">)</span> 
        <span class="token keyword">return</span> <span class="token keyword">false</span><span class="token punctuation">;</span> 
    
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>IsActive<span class="token punctuation">)</span> 
        <span class="token keyword">return</span> <span class="token keyword">false</span><span class="token punctuation">;</span> 

    <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>CreditScore <span class="token operator">&lt;</span> <span class="token number">700</span><span class="token punctuation">)</span> 
        <span class="token keyword">return</span> <span class="token keyword">false</span><span class="token punctuation">;</span> 

    <span class="token keyword">var</span> debt <span class="token operator">=</span> <span class="token keyword">await</span> _debtRepository<span class="token punctuation">.</span><span class="token function">GetOutstandingDebtAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Id<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    
    <span class="token keyword">return</span> debt <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">private</span> <span class="token keyword">async</span> Task <span class="token function">ApproveLoan</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span> 
<span class="token punctuation">{</span> 
    application<span class="token punctuation">.</span><span class="token function">Approve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
    
    <span class="token keyword">await</span> _loanRepository<span class="token punctuation">.</span><span class="token function">SaveAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    
    <span class="token keyword">await</span> _notificationService<span class="token punctuation">.</span><span class="token function">SendApprovalEmailAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Email<span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre><p>Note that the behavior of the <code>ApproveAsync</code> method remains exactly the same, but now each helper method has a single responsibility. The <code>ApproveAsync</code> method clearly demonstrates the operation&rsquo;s intent, while <code>CanBeApproved</code> encapsulates the eligibility rules and <code>ApproveLoan</code> performs only the approval itself.</p><p>The main goal of this rule is to avoid creating methods that attempt to do too many things at once. When evaluating each method individually, it is generally easier to understand the overall flow. Therefore, using concise methods is preferable.</p><h2 id="dont-use-the-else-keyword">2. Don&rsquo;t Use the ELSE Keyword</h2><p>The second rule suggests avoiding the <code>else</code> keyword. The idea is not that else is a bad language feature, but rather that its necessity often indicates a method is handling two different flows simultaneously.</p><p>To adhere to this rule, we can use strategies such as early returns or even polymorphism whenever there are multiple conditional behaviors.</p><p>Consider the method that cancels a loan request.</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">async</span> Task <span class="token function">Cancel</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Status <span class="token operator">==</span> LoanStatus<span class="token punctuation">.</span>Pending<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         application<span class="token punctuation">.</span><span class="token function">Cancel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

         <span class="token keyword">await</span> _loanRepository<span class="token punctuation">.</span><span class="token function">SaveAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">)</span><span class="token punctuation">;</span>

         <span class="token keyword">await</span> _notificationService<span class="token punctuation">.</span><span class="token function">SendCancellationEmailAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Email<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
     <span class="token keyword">else</span>
     <span class="token punctuation">{</span>
         _logger<span class="token punctuation">.</span><span class="token function">LogWarning</span><span class="token punctuation">(</span><span class="token string">"Loan {LoanId} cannot be cancelled because it is {Status}."</span><span class="token punctuation">,</span>
             application<span class="token punctuation">.</span>Id<span class="token punctuation">,</span>
             application<span class="token punctuation">.</span>Status<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><p>The <code>Cancel</code> method has two completely different flows: one for a successful operation and another for handling an invalid condition.</p><p>We can make this flow more streamlined by using a guard clause, a technique that involves checking for error conditions or special cases right at the beginning of a function or method, returning a value or throwing an error early if the requirements are not met.</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">async</span> Task <span class="token function">Cancel</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">if</span> <span class="token punctuation">(</span>application<span class="token punctuation">.</span>Status <span class="token operator">!=</span> LoanStatus<span class="token punctuation">.</span>Pending<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         _logger<span class="token punctuation">.</span><span class="token function">LogWarning</span><span class="token punctuation">(</span>
             <span class="token string">"Loan {LoanId} cannot be cancelled because it is {Status}."</span><span class="token punctuation">,</span>
             application<span class="token punctuation">.</span>Id<span class="token punctuation">,</span>
             application<span class="token punctuation">.</span>Status<span class="token punctuation">)</span><span class="token punctuation">;</span>

         <span class="token keyword">return</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>

     application<span class="token punctuation">.</span><span class="token function">Cancel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

     <span class="token keyword">await</span> _loanRepository<span class="token punctuation">.</span><span class="token function">SaveAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">)</span><span class="token punctuation">;</span>

     <span class="token keyword">await</span> _notificationService<span class="token punctuation">.</span><span class="token function">SendCancellationEmailAsync</span><span class="token punctuation">(</span>application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Email<span class="token punctuation">)</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</code></pre><p>The method now presents only the operation&rsquo;s main flow. The exceptional condition is handled right at the start, and execution stops immediately, making an <code>else</code> block unnecessary. This approach improves readability and clearly highlights the operation&rsquo;s &ldquo;happy path.&rdquo;</p><p>It is important to note that this rule does not dictate that <code>else</code> should never be used. There are situations where using it makes the code clearer, such as in simple expressions (like the ternary operator <code>?:</code>) or when two flows are of equal importance. The goal is to encourage methods with an easy-to-read flow, rather than eliminating <code>else</code> at all costs.</p><h2 id="wrap-all-primitives-and-strings">3. Wrap All Primitives and Strings</h2><p>The third rule recommends encapsulating primitive types (int, decimal, string, DateTime, etc.) in objects that represent domain concepts.</p><p>Although primitive types are simple, they can make the system much harder to understand because they do not enforce business rules. Consequently, any value valid for the type also becomes valid for the domain, even in situations where it makes no sense.</p><p>Consider the example below.</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoanApplication</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">decimal</span> Amount <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">private</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">decimal</span> InterestRate <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">private</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">int</span> Installments <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">private</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">LoanApplication</span><span class="token punctuation">(</span>
        <span class="token keyword">decimal</span> amount<span class="token punctuation">,</span>
        <span class="token keyword">decimal</span> interestRate<span class="token punctuation">,</span>
        <span class="token keyword">int</span> installments<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        Amount <span class="token operator">=</span> amount<span class="token punctuation">;</span>
        InterestRate <span class="token operator">=</span> interestRate<span class="token punctuation">;</span>
        Installments <span class="token operator">=</span> installments<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>This example presents a classic case of using primitive types. At first glance, there is nothing wrong with it. However, this implementation allows the creation of objects with invalid states:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">ProcessApplication</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">var</span> application <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LoanApplication</span><span class="token punctuation">(</span>
         <span class="token keyword">new</span> <span class="token class-name">Money</span><span class="token punctuation">(</span>50_000<span class="token punctuation">)</span><span class="token punctuation">,</span> 
         <span class="token keyword">new</span> <span class="token class-name">InterestRate</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">.</span>25m<span class="token punctuation">)</span><span class="token punctuation">,</span>
         <span class="token keyword">new</span> <span class="token class-name">InstallmentCount</span><span class="token punctuation">(</span><span class="token number">48</span><span class="token punctuation">)</span>
     <span class="token punctuation">)</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</code></pre><p>The compiler accepts all these values because they are valid for <code>decimal</code> and <code>int</code>, but they make no sense for a loan application, after all, they are negative or zero.</p><p>Alternatively, we can encapsulate these concepts in Value Objects.</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoanApplication</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> Money Amount <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> InterestRate InterestRate <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> InstallmentCount Installments <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">LoanApplication</span><span class="token punctuation">(</span>Money amount<span class="token punctuation">,</span> InterestRate interestRate<span class="token punctuation">,</span> InstallmentCount installments<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        Amount <span class="token operator">=</span> amount<span class="token punctuation">;</span>
        InterestRate <span class="token operator">=</span> interestRate<span class="token punctuation">;</span>
        Installments <span class="token operator">=</span> installments<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">sealed</span> record Money
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">decimal</span> Value <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">Money</span><span class="token punctuation">(</span><span class="token keyword">decimal</span> <span class="token keyword">value</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">value</span> <span class="token operator">&lt;=</span> <span class="token number">0</span><span class="token punctuation">)</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span><span class="token string">"Amount must be greater than zero."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        Value <span class="token operator">=</span> <span class="token keyword">value</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">sealed</span> record InterestRate
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">decimal</span> Value <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">InterestRate</span><span class="token punctuation">(</span><span class="token keyword">decimal</span> <span class="token keyword">value</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">value</span> <span class="token operator">&lt;</span> <span class="token number">0</span> <span class="token operator">||</span> <span class="token keyword">value</span> <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token punctuation">)</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span><span class="token string">"Interest rate must be between 0 and 100."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        Value <span class="token operator">=</span> <span class="token keyword">value</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">sealed</span> record InstallmentCount
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> Value <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">InstallmentCount</span><span class="token punctuation">(</span><span class="token keyword">int</span> <span class="token keyword">value</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">value</span> <span class="token operator">&lt;</span> <span class="token number">1</span><span class="token punctuation">)</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span>
                <span class="token string">"Installment count must be greater than zero."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">value</span> <span class="token operator">&gt;</span> <span class="token number">120</span><span class="token punctuation">)</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span>
                <span class="token string">"Installment count cannot exceed 120."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        Value <span class="token operator">=</span> <span class="token keyword">value</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Now, each type is responsible for validating its own rules, so invalid objects aren&rsquo;t created.</p><p>In this way, the code comes to represent real-world concepts, such as <a target="_blank" href="https://www.telerik.com/blogs/how-to-model-money-aspnet-core">Money</a>, Interest Rate and Number of Installments.</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">var</span> application <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LoanApplication</span><span class="token punctuation">(</span>
    <span class="token keyword">new</span> <span class="token class-name">Money</span><span class="token punctuation">(</span>50_000<span class="token punctuation">)</span><span class="token punctuation">,</span> 
    <span class="token keyword">new</span> <span class="token class-name">InterestRate</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">.</span>25m<span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">new</span> <span class="token class-name">InstallmentCount</span><span class="token punctuation">(</span><span class="token number">48</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>Notice that the code becomes much more expressive. We are now creating instances of business concepts rather than simply manipulating numbers and other data. Beyond readability, this approach centralizes validation logic and prevents the creation of objects in invalid states.</p><h2 id="first-class-collections">4. First-Class Collections</h2><p>The fourth rule recommends that a collection not be treated merely as a class property. Instead, it is preferable for a collection to have its own behavior.</p><p>Based on this rule, we should avoid creating properties that expose a <code>List&lt;T&gt;</code> and allow any part of the application to directly add, remove or manipulate its elements. The problem is that, when this happens, the rules defined for that collection end up scattered throughout the code that uses it.</p><p>Consider a loan system where a request consists of multiple installments.</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">namespace</span> PracticingObjectCalisthenics
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoanApplication</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">public</span> List<span class="token operator">&lt;</span>Installment<span class="token operator">&gt;</span> Installments <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

        <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">AddInstallment</span><span class="token punctuation">(</span>Installment installment<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            Installments<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>installment<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Note that any code with access to the list can manipulate it directly:</p><pre class=" language-csharp"><code class="prism  language-csharp">application<span class="token punctuation">.</span>Installments<span class="token punctuation">.</span><span class="token function">Clear</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

application<span class="token punctuation">.</span>Installments<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Installment</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">DateOnly</span><span class="token punctuation">(</span><span class="token number">2026</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

application<span class="token punctuation">.</span>Installments<span class="token punctuation">.</span><span class="token function">RemoveAt</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>This means that <code>LoanApplication</code> does not have real control over its own collection.</p><p>A possible solution is to turn the collection itself into an object responsible for its own behavior.</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoanApplication</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">readonly</span> Installments _installments <span class="token operator">=</span> <span class="token keyword">new</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

     <span class="token keyword">public</span> IReadOnlyCollection<span class="token operator">&lt;</span>Installment<span class="token operator">&gt;</span> InstallmentItems <span class="token operator">=</span><span class="token operator">&gt;</span>
         _installments<span class="token punctuation">.</span>Items<span class="token punctuation">;</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">AddInstallment</span><span class="token punctuation">(</span>Installment installment<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         _installments<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>installment<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">sealed</span> <span class="token keyword">class</span> <span class="token class-name">Installments</span>
<span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">readonly</span> List<span class="token operator">&lt;</span>Installment<span class="token operator">&gt;</span> _items <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> IReadOnlyCollection<span class="token operator">&lt;</span>Installment<span class="token operator">&gt;</span> Items <span class="token operator">=</span><span class="token operator">&gt;</span>
        _items<span class="token punctuation">.</span><span class="token function">AsReadOnly</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">Add</span><span class="token punctuation">(</span>Installment installment<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>_items<span class="token punctuation">.</span>Count <span class="token operator">&gt;=</span> <span class="token number">120</span><span class="token punctuation">)</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span>
                <span class="token string">"A loan cannot have more than 120 installments."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        _items<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>installment<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">decimal</span> <span class="token function">TotalAmount</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> _items<span class="token punctuation">.</span><span class="token function">Sum</span><span class="token punctuation">(</span>x <span class="token operator">=</span><span class="token operator">&gt;</span> x<span class="token punctuation">.</span>Amount<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>The <code>(Installments)</code> collection now knows the rules that determine its elements. Consequently, we can no longer add items to it without using its own methods:</p><pre class=" language-csharp"><code class="prism  language-csharp">application<span class="token punctuation">.</span>Installments<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>installment<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Does not compile</span>
</code></pre><p>To add an item to the collection now, we need to use its specific method:</p><pre class=" language-csharp"><code class="prism  language-csharp">application<span class="token punctuation">.</span><span class="token function">AddInstallment</span><span class="token punctuation">(</span>installment<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// The code compiles now</span>
</code></pre><p>The main idea behind the First-Class Collections rule is that a collection can be much more than a simple <code>List&lt;T&gt;</code>. You should favor this approach when a collection has its own rules, validations or behaviors that need to be represented in the model.</p><p>On the other hand, in scenarios where collections are used to transport data, such as a list used to construct an API response, there is likely no need to apply this rule.</p><h2 id="one-dot-per-line">5. One Dot Per Line</h2><p>The fifth rule recommends preventing an object from knowing the internal structure of other objects. One of the most common signs that code is violating this rule is the presence of chained calls, where an object accesses another object, which accesses another and so on.</p><p>Imagine that, during loan approval, we need to record the customer&rsquo;s city:</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">LogLoanApproval</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    _logger<span class="token punctuation">.</span><span class="token function">LogInformation</span><span class="token punctuation">(</span>
        <span class="token string">"Loan {LoanId} approved for customer from {City}."</span><span class="token punctuation">,</span>
        application<span class="token punctuation">.</span>Id<span class="token punctuation">,</span>
        application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>Address<span class="token punctuation">.</span>City<span class="token punctuation">.</span>Name<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The problem here is not necessarily the number of points, but the fact that <code>LogLoanApproval</code> knows too much about the internal structure of <code>LoanApplication</code>. Thus, we have the following schema: <code>LoanApplication -&gt; Customer -&gt; Address -&gt; City -&gt; Name</code>.</p><p>If the structure changes from <code>application.Customer.Address.City.Name</code> to <code>application.Customer.Residence.CityName</code>, this code will also need to be updated.</p><p><strong>✅ After</strong></p><p>We can delegate the responsibility to the object that holds the information:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Customer</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> Address Address <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">string</span> CityName <span class="token operator">=</span><span class="token operator">&gt;</span> Address<span class="token punctuation">.</span>City<span class="token punctuation">.</span>Name<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><pre class=" language-csharp"><code class="prism  language-csharp">   <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">LogLoanApproval</span><span class="token punctuation">(</span>LoanApplication application<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        _logger<span class="token punctuation">.</span><span class="token function">LogInformation</span><span class="token punctuation">(</span>
            <span class="token string">"Loan {LoanId} approved for customer from {City}."</span><span class="token punctuation">,</span>
            application<span class="token punctuation">.</span>Id<span class="token punctuation">,</span>
            application<span class="token punctuation">.</span>Customer<span class="token punctuation">.</span>CityName<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre><p>Now, anyone using <code>Customer</code> does not need to know its internal structure. If the implementation of <code>Address</code> or <code>City</code> changes, the impact is confined to the <code>Customer</code> itself.</p><p>The goal of this rule is not to eliminate all navigation chains, but rather to prevent external code from depending on the internal structure of other objects, which is why the <code>Address.City.Name</code> chain still exists within <code>Customer</code>. By shifting this knowledge to <code>Customer</code>, only <code>Customer</code> needs to be updated if the internal structure of <code>Address</code> or <code>City</code> changes.</p><h2 id="dont-abbreviate">6. Don&rsquo;t Abbreviate</h2><p>The sixth rule is probably one of the simplest, yet still essential rules: Do not abbreviate the names of variables, methods, classes or properties.</p><p>The idea is to prioritize code clarity. Short names may be faster to type, but the problem is that they usually require more cognitive effort to figure out what the abbreviation means. Consider an example:</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">CalcTot</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">var</span> usr <span class="token operator">=</span> <span class="token function">GetUsr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token keyword">var</span> ords <span class="token operator">=</span> usr<span class="token punctuation">.</span>Orders<span class="token punctuation">;</span>
     <span class="token keyword">var</span> tot <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

     <span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token keyword">var</span> ord <span class="token keyword">in</span> ords<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">var</span> amt <span class="token operator">=</span> ord<span class="token punctuation">.</span>Amount<span class="token punctuation">;</span>
         tot <span class="token operator">+</span><span class="token operator">=</span> amt<span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><p>The code might be quickly understood by the person who wrote it, but the reader has to interpret various abbreviations, such as &ldquo;CalcTot&rdquo; for &ldquo;Calculate Total&rdquo; and &ldquo;ords&rdquo; for &ldquo;Orders.&rdquo; There is no real advantage to hiding this information.</p><p>If we write the words as they actually are, we get the following:</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">CalculateTotal</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">var</span> user <span class="token operator">=</span> <span class="token function">GetUser</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token keyword">var</span> orders <span class="token operator">=</span> user<span class="token punctuation">.</span>Orders<span class="token punctuation">;</span>
     <span class="token keyword">var</span> total <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>

     <span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token keyword">var</span> order <span class="token keyword">in</span> orders<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">var</span> amount <span class="token operator">=</span> order<span class="token punctuation">.</span>Amount<span class="token punctuation">;</span>
         total <span class="token operator">+</span><span class="token operator">=</span> amount<span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><p>The code can now be understood without any further explanation.</p><h2 id="keep-all-entities-small">7. Keep All Entities Small</h2><p>The seventh rule recommends keeping classes and other model elements small. The idea is to avoid objects that accumulate too many responsibilities.</p><p>This does not mean that a class with 49 lines, for example, is better than one with 51. Instead, it encourages viewing size as a warning sign: when a class grows too large, there are usually responsibilities that could be transferred to other objects.</p><p>Consider a class responsible for representing an order:</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CustomerOrder</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">public</span> <span class="token keyword">int</span> Id <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

     <span class="token keyword">public</span> List<span class="token operator">&lt;</span>OrderItem<span class="token operator">&gt;</span> Items <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

     <span class="token keyword">public</span> <span class="token keyword">decimal</span> <span class="token function">CalculateTotal</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">return</span> Items<span class="token punctuation">.</span><span class="token function">Sum</span><span class="token punctuation">(</span>item <span class="token operator">=</span><span class="token operator">&gt;</span> item<span class="token punctuation">.</span>Price <span class="token operator">*</span> item<span class="token punctuation">.</span>Quantity<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">Validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">if</span> <span class="token punctuation">(</span>Items<span class="token punctuation">.</span>Count <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
             <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span><span class="token string">"Order must have at least one item."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

         <span class="token keyword">if</span> <span class="token punctuation">(</span>Items<span class="token punctuation">.</span><span class="token function">Any</span><span class="token punctuation">(</span>item <span class="token operator">=</span><span class="token operator">&gt;</span> item<span class="token punctuation">.</span>Quantity <span class="token operator">&lt;=</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
             <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span><span class="token string">"Invalid item quantity."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">SendConfirmationEmail</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token comment">// Send email...</span>
     <span class="token punctuation">}</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">ExportToCsv</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token comment">// Generate CSV...</span>
     <span class="token punctuation">}</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">Save</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token comment">// Save to database...</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><p>The problem here is not the number of lines, but rather the fact that the class has responsibilities belonging to different contexts such as representing the order, calculating the total, validating the order, sending emails, exporting to CSV and persisting data. As new features are added, the <code>Order</code> class tends to grow larger and larger.</p><p>To avoid this disproportionate growth, we can keep <code>Order</code> focused on the behavior that truly belongs to the order:</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CustomerOrder</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">readonly</span> List<span class="token operator">&lt;</span>OrderItem<span class="token operator">&gt;</span> _items <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

     <span class="token keyword">public</span> IReadOnlyCollection<span class="token operator">&lt;</span>OrderItem<span class="token operator">&gt;</span> Items <span class="token operator">=</span><span class="token operator">&gt;</span> _items<span class="token punctuation">;</span>

     <span class="token keyword">public</span> <span class="token keyword">decimal</span> <span class="token function">CalculateTotal</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">return</span> _items<span class="token punctuation">.</span><span class="token function">Sum</span><span class="token punctuation">(</span>item <span class="token operator">=</span><span class="token operator">&gt;</span> item<span class="token punctuation">.</span>Price <span class="token operator">*</span> item<span class="token punctuation">.</span>Quantity<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">AddItem</span><span class="token punctuation">(</span>OrderItem item<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         ArgumentNullException<span class="token punctuation">.</span><span class="token function">ThrowIfNull</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">;</span>

         _items<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><p>The validation can reside in its own component:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderValidator</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">Validate</span><span class="token punctuation">(</span>CustomerOrder order<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>order<span class="token punctuation">.</span>Items<span class="token punctuation">.</span>Count <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span><span class="token string">"Order must have at least one item."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Email sending can be the responsibility of a dedicated service:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderNotificationService</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">async</span> Task <span class="token function">SendConfirmationAsync</span><span class="token punctuation">(</span>Order order<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token comment">// Send email...</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>And persistence is handled by a repository:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderRepository</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">async</span> Task <span class="token function">SaveAsync</span><span class="token punctuation">(</span>Order order<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token comment">// Save order record...</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Now, each class has a much clearer responsibility. It is important to highlight that the true goal is to identify responsibilities that should not be grouped together.</p><p>When encountering a very large class, we might ask ourselves: &ldquo;If I need to change this part of the behavior, how many other responsibilities within this class might be affected?&rdquo;</p><p>If the answer involves different reasons for modifying the class, there is likely an opportunity to separate the responsibilities.</p><h2 id="no-classes-with-more-than-two-instance-variables">8. No Classes with More Than Two Instance Variables</h2><p>The eighth rule recommends that a class have at most two instance variables. The intention is not to claim that a class with three fields is automatically poorly designed, but rather to encourage the developer to recognize when a class is accumulating information that could belong to other objects.</p><p>Consider a simple class to represent a student:</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Student</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _name<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _email<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _phone<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _document<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _street<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _city<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _state<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</code></pre><p>The problem here is that the <code>Student</code> class represents multiple domain concepts simultaneously, such as personal information, contact details, identification documents and addresses. We can make these concepts explicit by using dedicated objects.</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Student</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> PersonalInformation _personalInformation<span class="token punctuation">;</span>
     <span class="token keyword">private</span> Address _address<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">PersonalInformation</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _name<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _document<span class="token punctuation">;</span>
     <span class="token keyword">private</span> ContactInformation _contactInformation<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ContactInformation</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _email<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _phone<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Address</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _street<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _city<span class="token punctuation">;</span>
     <span class="token keyword">private</span> <span class="token keyword">string</span> _state<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
</code></pre><p>We now have a model where the concepts are more explicit:</p><pre class=" language-bash"><code class="prism  language-bash">- Student
- PersonalInformation
- Name
- Document
- ContactInformation
- Email
- Phone
- Address
- Street
- City
- State
</code></pre><p>The most important thing here is not simply reducing the <code>Student</code> class from seven variables to two. The real benefit lies in identifying concepts that were hidden within the class and transforming them into explicit objects. Therefore, this rule should be viewed as a constraint to encourage the discovery of good objects, rather than as a mathematical rule.</p><h2 id="no-getterssettersproperties">9. No Getters/Setters/Properties</h2><p>The ninth and final rule recommends avoiding the exposure of an object&rsquo;s internal state via getters, setters or properties without due care.</p><p>In this regard, the rule emphasizes that an object should be responsible for its own state and behavior. Instead of allowing any part of the application to modify its properties directly, we should provide methods that express the operations permitted by the domain.</p><p>Consider a simple example:</p><p><strong>❌ Before</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoyaltyAccount</span>
<span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> Points <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>The problem is that any part of the application can modify the points directly:</p><pre class=" language-csharp"><code class="prism  language-csharp">account<span class="token punctuation">.</span>Points <span class="token operator">+</span><span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>

account<span class="token punctuation">.</span>Points <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">500</span><span class="token punctuation">;</span>
</code></pre><p>In this way, the class has no mechanism to protect its state. A more object-oriented approach is to encapsulate the behavior:</p><p><strong>✅ After</strong></p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoyaltyAccount</span>
 <span class="token punctuation">{</span>
     <span class="token keyword">private</span> <span class="token keyword">int</span> _points<span class="token punctuation">;</span>

     <span class="token keyword">public</span> <span class="token keyword">int</span> Points <span class="token operator">=</span><span class="token operator">&gt;</span> _points<span class="token punctuation">;</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">EarnPoints</span><span class="token punctuation">(</span><span class="token keyword">int</span> points<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">if</span> <span class="token punctuation">(</span>points <span class="token operator">&lt;=</span> <span class="token number">0</span><span class="token punctuation">)</span>
             <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span>
                 <span class="token string">"Points must be greater than zero."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

         _points <span class="token operator">+</span><span class="token operator">=</span> points<span class="token punctuation">;</span>
     <span class="token punctuation">}</span>

     <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">RedeemPoints</span><span class="token punctuation">(</span><span class="token keyword">int</span> points<span class="token punctuation">)</span>
     <span class="token punctuation">{</span>
         <span class="token keyword">if</span> <span class="token punctuation">(</span>points <span class="token operator">&lt;=</span> <span class="token number">0</span><span class="token punctuation">)</span>
             <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span>
                 <span class="token string">"Points must be greater than zero."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

         <span class="token keyword">if</span> <span class="token punctuation">(</span>points <span class="token operator">&gt;</span> _points<span class="token punctuation">)</span>
             <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">DomainException</span><span class="token punctuation">(</span>
                 <span class="token string">"Insufficient points."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

         _points <span class="token operator">-</span><span class="token operator">=</span> points<span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><p>Now, the consumer does not need to manipulate the state directly, the object itself decides how these operations should be performed.</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">var</span> account <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">LoyaltyAccount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  account<span class="token punctuation">.</span><span class="token function">EarnPoints</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  account<span class="token punctuation">.</span><span class="token function">RedeemPoints</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token comment">//It doesn't compile now</span>
  <span class="token comment">//account.Points += 100;</span>
</code></pre><p>It is worth noting that this rule does not dictate that we should stop using properties altogether. Rather, the goal is to prevent our classes from turning into mere &ldquo;data bags,&rdquo; where all the logic ends up scattered across other components.</p><p>One question we might ask is: Does the object merely hold data, or does it also need to know what to do with that data? If it does need to know, that is a strong indication that simple properties with only getters and setters should be avoided.</p><h2 id="conclusion">Conclusion</h2><p>Throughout this post, we explored the nine rules of Object Calisthenics and saw how each addresses issues still prevalent in modern applications: anemic domain models, classes with excessive responsibilities, tight coupling between objects and business rules scattered across layers.</p><p>It is worth noting that these rules were conceived as an exercise rather than a mandatory checklist. Their true value lies in identifying opportunities to apply them, especially in scenarios involving greater domain complexity, such as with entities and value objects.</p><p>For code involving infrastructure, DTOs, controllers and other boundary layers, a simpler approach is usually more appropriate.</p><p>A good first step toward putting these ideas into practice is to select a class from your current project that already seems problematic and try applying a few of the nine rules to it, the results might surprise you.</p><p><a href="https://www.telerik.com/blogs/aspnet-core-basics-mastering-object-oriented-programming-concepts" target="_blank">Object-oriented programming</a> offers us excellent tools, and Object Calisthenics is a way to help us truly make the most of them.</p><hr /><blockquote><p>Keep exploring <a href="https://www.telerik.com/blogs/tag/asp-net-core-basics" target="_blank">ASP.NET Basics</a> topics.</p></blockquote><img src="https://feeds.telerik.com/link/10827/17516163.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:8bfdab23-fb85-4ce8-b6d4-bc7bf8f138f0</id>
    <title type="text">Blazor Basics: Persisting Component State in Blazor with .NET 10</title>
    <summary type="text">Learn how to reuse state between prerendering and establishing interactivity in Blazor components.</summary>
    <published>2026-11-03T21:23:46Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Claudio Bernasconi </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17514740/blazor-basics-persisting-component-state-net-10"/>
    <content type="text"><![CDATA[<p><span class="featured">Learn how to reuse state between prerendering and establishing interactivity in Blazor components.</span></p><p>In Blazor, prerendering lets pages render quickly on the server, giving users useful content while the application becomes interactive. It also makes the initial HTML available to search engines.</p><p>However, prerendering comes with an important consequence: a component can be initialized twice. It is first rendered on the server during prerendering and then initialized again when the selected interactive render mode takes over. This applies not only to Interactive Server, but also to Interactive WebAssembly and Interactive Auto.</p><p>This can become a problem when a component performs expensive work during initialization, such as calling a database or an external API.</p><p>In this article, we&rsquo;ll learn how to avoid that unnecessary work by persisting component state between prerendering and interactive rendering.</p><p>You can <a href="https://github.com/claudiobernasconi/BlazorPersistentState">access the code on GitHub</a>.</p><h2 id="the-default-behavior-of-page-components-and-prerendering-in-blazor">The Default Behavior of Page Components and Prerendering in Blazor</h2><p>We often see code like this in page components:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token operator">&lt;</span>PageTitle<span class="token operator">&gt;</span>Products<span class="token operator">&lt;</span><span class="token operator">/</span>PageTitle<span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>h1<span class="token operator">&gt;</span>Products<span class="token operator">&lt;</span><span class="token operator">/</span>h1<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span>QuickGrid Items<span class="token operator">=</span><span class="token string">"@Data?.AsQueryable()"</span><span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>PropertyColumn Property<span class="token operator">=</span><span class="token string">"p =&gt; p.Title"</span> Title<span class="token operator">=</span><span class="token string">"Title"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>PropertyColumn Property<span class="token operator">=</span><span class="token string">"p =&gt; p.Description"</span> Title<span class="token operator">=</span><span class="token string">"Description"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
  <span class="token operator">&lt;</span>PropertyColumn Property<span class="token operator">=</span><span class="token string">"p =&gt; p.Price"</span> Title<span class="token operator">=</span><span class="token string">"Price"</span> Format<span class="token operator">=</span><span class="token string">"C2"</span> <span class="token operator">/</span><span class="token operator">&gt;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>QuickGrid<span class="token operator">&gt;</span>

<span class="token keyword">public</span> IEnumerable<span class="token operator">&lt;</span>Product<span class="token operator">&gt;</span><span class="token operator">?</span> Data <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token keyword">async</span> <span class="token keyword">override</span> Task <span class="token function">OnInitializedAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  Data <span class="token operator">=</span> <span class="token keyword">await</span> ProductService<span class="token punctuation">.</span><span class="token function">GetProductsAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The problem here is that with Prerending enabled, the <code>OnInitializedAsync</code> lifecycle method will be called twice. If the data provided by the service is the same, the user might not see anything change on the screen.</p><p>However, imagine the following implementation of the <code>GetProductsAsync</code> method:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> <span class="token keyword">async</span> Task<span class="token operator">&lt;</span>IEnumerable<span class="token operator">&lt;</span>Product<span class="token operator">&gt;</span><span class="token operator">&gt;</span> <span class="token function">GetProductsAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span><span class="token string">"GetProductsAsync"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">var</span> random <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token punctuation">[</span>
    <span class="token keyword">new</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
      Title <span class="token operator">=</span> <span class="token string">"Laptop"</span><span class="token punctuation">,</span>
      Description <span class="token operator">=</span> <span class="token string">"15-inch productivity laptop"</span><span class="token punctuation">,</span>
      Price <span class="token operator">=</span> random<span class="token punctuation">.</span><span class="token function">Next</span><span class="token punctuation">(</span><span class="token number">800</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token keyword">new</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
      Title <span class="token operator">=</span> <span class="token string">"Keyboard"</span><span class="token punctuation">,</span>
      Description <span class="token operator">=</span> <span class="token string">"Mechanical wireless keyboard"</span><span class="token punctuation">,</span>
      Price <span class="token operator">=</span> random<span class="token punctuation">.</span><span class="token function">Next</span><span class="token punctuation">(</span><span class="token number">70</span><span class="token punctuation">,</span> <span class="token number">135</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token comment">/* additional items omitted */</span>
  <span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>This example uses randomly generated values for the <code>Price</code> property of each <code>Product</code>. What might seem a bit artificial at first makes total sense. Let me explain.</p><p>We simulate loading the stock from an external API or the price from a remote service. It is not guaranteed that the product costs the same all day, or that another user didn&rsquo;t purchase a product between the two times <code>GetProductsAsync</code> is called.</p><p>If we add a log statement in the <code>GetProductsAsync</code> method, we will see the method is called twice during page load.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/log-messages-without-persisting-state.png?sfvrsn=f3750690_2" title="Log Messages for rendering a page component in Blazor with Prerending enabled" alt="A console window showing the OnInitializedAsync method and the GetProductsAsync method both called twice." /></p><p>On the screen, the user will see two different prices for the same item. The first value appears quickly, then the second replaces it.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/prerendering-state1.png?sfvrsn=28c7cbc2_2" title="The Blazor app in the browser with the values from prerendering" alt="A browser with the running Blazor app and a table with products showing the prices as 981, 104, and 51." /></p><p>This is the screen after the prerendering.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/prerendering-state2.png?sfvrsn=eb04c558_2" title="The Blazor app in the browser with the values after the interactivity has been established" alt="A browser with the running Blazor app and a table with products showing the prices as 849, 113, and 46." /></p><p>And this is the screen after the component interactivity has been initialized.</p><h2 id="blazor-component-lifecycle-with-prerendering">Blazor Component Lifecycle with Prerendering</h2><p>Let&rsquo;s take a step back and look at how and why the <code>OnInitializedAsync</code> method is called twice when rendering a page in a Blazor web application with Prerendering enabled.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/blazor-component-lifecycle-oninitializedasync.png?sfvrsn=130a2cc_2" title="A chart showing that Prerendering and Blazor Server interactivity both call the OnInitializedAsync method" alt="A chart with a Blazor component that uses prerendering and Blazor Server interactivity. Both call the OnInitializedAsync method." /></p><p>The user initiates an HTTP request by visiting the web application through the browser. The server prerenders the initial page and sends the HTML to the client, where the browser renders it.</p><p>Meanwhile, Blazor becomes interactive, and the component reinitializes. For example, on click, handlers are enabled.</p><p>The component is initialized once during prerendering and then initialized again when the interactive render mode takes over. As a result, <code>OnInitializedAsync</code> can run twice, causing code that performs data loading or other initialization work to execute twice.</p><p>This behavior is the same regardless of the rendering mode (<code>InteractiveServer</code>, <code>InteractiveWebAssembly</code>, <code>InteractiveAuto</code>).</p><h2 id="persisting-the-prerendered-state-between-oninitializedasync-calls">Persisting The Prerendered State Between OnInitializedAsync Calls</h2><p>Now that we know what&rsquo;s happening, let&rsquo;s learn how to fix the problem. In our example code, we want to fetch the data from the <code>ProductService</code> only once.</p><p>A simple solution is to store the data in the <code>Data</code> property during prerendering and keep it available so that we can reuse it when the component becomes interactive and the <code>OnInitializedAsync</code> method is called again.</p><p>First, let&rsquo;s make sure we check that the <code>Data</code> property isn&rsquo;t <code>null</code> before we access the <code>ProductService</code>.</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">public</span> IEnumerable<span class="token operator">&lt;</span>Product<span class="token operator">&gt;</span><span class="token operator">?</span> Data <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token keyword">async</span> <span class="token keyword">override</span> Task <span class="token function">OnInitializedAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>Data <span class="token keyword">is</span> <span class="token keyword">null</span><span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
     Data <span class="token operator">=</span> <span class="token keyword">await</span> ProductService<span class="token punctuation">.</span><span class="token function">GetProductsAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>But how do we persist the data in the <code>Data</code> property once we get it returned from the <code>ProductService</code> by calling its <code>GetProductsAsync</code> method?</p><p>That&rsquo;s exactly the problem the <code>PersistentState</code> attribute helps solve in .NET 10.</p><p>We add the <code>PersistentState</code> attribute to the <code>Data</code> property.</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token punctuation">[</span>PersistentState<span class="token punctuation">]</span>
<span class="token keyword">public</span> IEnumerable<span class="token operator">&lt;</span>Product<span class="token operator">&gt;</span><span class="token operator">?</span> Data <span class="token punctuation">{</span> <span class="token keyword">get</span><span class="token punctuation">;</span> <span class="token keyword">set</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>

<span class="token keyword">protected</span> <span class="token keyword">async</span> <span class="token keyword">override</span> Task <span class="token function">OnInitializedAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>Data <span class="token keyword">is</span> <span class="token keyword">null</span><span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
    Data <span class="token operator">=</span> <span class="token keyword">await</span> ProductService<span class="token punctuation">.</span><span class="token function">GetProductsAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>That&rsquo;s all we need to do. When you restart the application, you will notice that the prices do not change when reloading the Products page.</p><p>Under the hood, the data inside the <code>Data</code> property will be serialized so that it can be deserialized during the second <code>OnInitializedAsync</code> call. <strong>Blazor isn&rsquo;t persisting the component itself. It&rsquo;s persisting the value of the property.</strong></p><p><strong>Note:</strong> You can put log statements in the <code>OnInitializedAsync</code> lifecycle method and the <code>GetProductsAsync</code> method of the ProductService. You&rsquo;ll notice that with the <code>PersistentState</code> attribute applied, there will be two <code>OnInitializedAsync</code> calls and only one <code>GetProductsAsync</code> call. On the contrary, without the <code>PersistentState</code> attribute, there will be a <code>GetProductsAsync</code> call for each <code>OnInitializedAsync</code> method call.</p><h2 id="what-data-should-we-persist">What Data Should We Persist?</h2><p>Data returned from a backend API is an obvious candidate to be persisted between prerendering and component interactivity. But what about other data?</p><p>The following list is my personal guideline that can help you get a sense for when to use or avoid using the PersistentState attribute in your projects:</p><h3 id="good-candidates">Good Candidates</h3><ul><li>Data retrieved during prerendering</li><li>Expensive-to-create serializable view-model data</li><li>Read-only lookup data</li><li>Initial form state</li><li>Data needed to make the interactive UI match the prerendered UI</li></ul><h3 id="bad-candidates">Bad candidates</h3><ul><li>Passwords</li><li>Secrets</li><li>Huge datasets</li><li>Sensitive information</li><li>Objects containing infrastructure dependencies</li><li>Things that should really live in a database</li></ul><p>There&rsquo;s an important security angle here. For client-side rendering, persisted state is exposed to the browser, so don&rsquo;t include sensitive/private information.</p><p>With interactive server rendering, <a href="http://ASP.NET">ASP.NET</a> Core Data Protection protects the transferred data, but you still need to reason about what you&rsquo;re persisting. InteractiveAuto and InteractiveWebAssembly need client-side exposure rules considered.</p><p><strong>Tip:</strong> If the state has to reach an Interactive WebAssembly component, assume that the persisted representation can ultimately be observed by the client. Don&rsquo;t use persistent component state as a mechanism for hiding secrets, authorization information, passwords or other sensitive data.</p><h2 id="state-in-blazor-web-applications">State in Blazor Web Applications</h2><p>The PersistentState attribute solves exactly what this article shows. It persists the component state between prerendering and component interactivity.</p><p>In Blazor web applications, we need to handle different types of state. The PersistentState attribute is a small part of a big puzzle.</p><p>The following table shows different types of state, a specific example, and a best practice for handling that state.</p><table><style>table, th, td {
  border: 1px;
  border-color: #bdbdba;
  border-style: dotted;
  border-collapse: collapse;
  margin-right: auto;
  padding:0in 5.4pt 0in 5.4pt;
  text-align :left;
}
</style>
 <thead><tr><th><strong>Kind of state</strong></th><th><strong>Example</strong></th><th><strong>Where it belongs</strong></th></tr></thead><tbody><tr><td>Component state</td><td>Selected tab</td><td>Component</td></tr><tr><td>Navigation state</td><td>Page 3 of a grid</td><td>URL</td></tr><tr><td>App state</td><td>Current user preferences</td><td>State container/service</td></tr><tr><td>Persisted application data</td><td>Shopping cart/order</td><td>Database/server storage</td></tr><tr><td>Prerendered state</td><td>Data fetched during SSR</td><td>PersistentComponentState</td></tr><tr><td>Browser state</td><td>Theme preference</td><td>Browser storage</td></tr></tbody></table><br /><p>The <code>PersistentState</code> attribute should only be used to persist the state between prerendering a component and its interactivity initialization.</p><h2 id="conclusion">Conclusion</h2><p>Prerendering is an important part of building fast Blazor web applications, but it also means that components can be initialized more than once as they transition from prerendered HTML to an interactive application.</p><p>If the component initialization performs expensive work, such as retrieving data from a backend service or database, that work can be executed twice when a component becomes interactive.</p><p>The <code>PersistentState</code> attribute provides a simple way to preserve the data returned by a backend service between these two phases, allowing the interactive component to reuse data that was already retrieved during prerendering.</p><p>However, <code>PersistentState</code> isn&rsquo;t a replacement for Blazor&rsquo;s other state-management approaches. It is specifically useful for carrying state across the boundary between prerendering and interactive rendering.</p><p>If you want to learn more about Blazor development, watch my <a target="_blank" href="https://www.youtube.com/playlist?list=PLwISgxnkpZGL_LhTQCWwp-WCzupv7lcp0">free Blazor Crash Course</a> on YouTube. And stay tuned to the Telerik blog for more <a href="https://www.telerik.com/blogs/tag/blazor-basics">Blazor Basics</a>.</p><img src="https://feeds.telerik.com/link/10827/17514740.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:7384ed87-7fa3-4f96-81f2-70a7abe57f25</id>
    <title type="text">Introduction to gRPC as a Tool for Connecting Microservices</title>
    <summary type="text">Learn how to build and connect to gRPC servers by creating a movie listing microservice. We’ll define an API contract using Protocol Buffers, set up a NestJS gRPC server with streaming support, and connect clients using both grpcurl and .NET.</summary>
    <published>2026-11-02T17:54:51Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Christian Nwamba </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17513937/introduction-grpc-tool-connecting-microservices"/>
    <content type="text"><![CDATA[<p><span class="featured">Learn how to build and connect to gRPC servers by creating a movie listing microservice. We&rsquo;ll define an API contract using Protocol Buffers, set up a NestJS gRPC server with streaming support, and connect clients using both grpcurl and .NET.</span></p><p>The microservices architectural style breaks applications into smaller, independent services that can use different technologies and communicate with each other to accomplish tasks.</p><p>Services communicate by sending messages or emitting events through channels connecting them. gRPC (Google Remote Procedure Call) is a framework created by Google in 2016 that makes it easy for microservices to communicate with each other.</p><h2 id="prerequisites">Prerequisites</h2><p>This article assumes you have:</p><ul><li>Familiarity with REST or <a target="_blank" href="https://graphql.org/">GraphQL</a> APIs</li><li>Basic programming knowledge, preferably in <a target="_blank" href="https://www.typescriptlang.org/">TypeScript</a></li></ul><h2 id="microservices-communication-unpacked">Microservices Communication Unpacked</h2><p>Interprocess communication (IPC) is how processes share information and coordinate tasks. When processes run on the same machine, they use techniques like message passing or shared memory. When they&rsquo;re distributed across multiple machines (like in microservices), they communicate over the network. To simplify this, microservices communication is IPC that happens over the network.</p><p>Whether processes are local or distributed, they need these key components to communicate:</p><ul><li><strong>Client/Producer</strong>: The process initiating communication</li><li><strong>Server/Consumer</strong>: The process receiving communication</li><li><strong>Message or Event</strong>: What gets sent between them</li><li><strong>Communication Channel</strong>: The path the data travels</li><li><strong>Protocol</strong>: The rules for encoding and decoding messages</li></ul><p>For example, when a browser (client) makes an HTTP POST request to create a product, it establishes a TCP connection to the server. The payload (JSON) representing the product information is serialized and sent in the request. The server processes it and sends back a response.</p><p>Microservices use the same components, but add some key differences:</p><ul><li><strong>Communication Patterns:</strong> Microservices support two patterns. The request-response pattern is like a typical HTTP request, where the client sends a request and waits for a response. This is what gRPC uses. Microservices also support event-based messaging, where the client sends one or more messages without expecting a response. The server can process them immediately or later, asynchronously.</li><li><strong>Network Mechanisms:</strong> While HTTP is the most common way to connect distributed processes, microservices also use other mechanisms. gRPC is built on top of HTTP by default. Other options include NATS, Redis, MQTT, Kafka and RabbitMQ. Some are HTTP-based, some are not.</li></ul><h2 id="grpc-in-clear-terms">gRPC in Clear Terms</h2><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/how-grpc-works.png?sfvrsn=aa22d85e_2" title="How gRPC works" alt="How gRPC works" /></p><p>gRPC&rsquo;s goal is to allow any two distributed processes to communicate, regardless of their runtime or programming language.</p><p>As a remote procedure framework, gRPC provides the necessary abstractions that allow the client to call functions on the server as if they were local. It handles all the complexity behind the scenes: connection management, serialization, encoding, transportation and decoding results.</p><p>Here are some of gRPC&rsquo;s key highlights:</p><ul><li><strong>Contract-First Approach:</strong> The contract is a file that defines the functions the server exposes, along with their parameters and return types (called message types in gRPC). The server implements these functions, and the client calls them as needed. The contract also handles message encoding and decoding. gRPC uses Protocol Buffers (protobuf) by default, but also supports JSON, Thrift, Avro and FlatBuffers. This improves development since clients don&rsquo;t need to remember endpoint names or parse data, and servers only focus on handling requests and sending responses.</li><li><strong>Type Safety:</strong> Since gRPC uses API contracts, it is type-safe and helps catch type errors at compile time, not at runtime like REST APIs do.</li><li><strong>Built on HTTP/2:</strong> gRPC uses HTTP/2, a binary protocol that improves speed and efficiency with the following advantages:
    <ul><li><strong>Binary frames:</strong> Messages are sent as binary, which is faster than text-based protocols like HTTP/1.1</li><li><strong>Multiplexing:</strong> Multiple requests and responses travel over one TCP connection. The server can prioritize requests and return responses in any order. This solves HTTP/1.1&rsquo;s head-of-line blocking problem</li><li><strong>Header compression:</strong> Uses HPACK compression for more efficient headers and better performance</li></ul></li><li><strong>Request-Response Pattern:</strong> gRPC uses the request-response pattern. The client sends a request, the server processes it, and sends back a response.</li><li><strong>Language Agnostic:</strong> gRPC is platform and language agnostic, supported by 13+ languages.</li></ul><h2 id="key-uses">Key Uses</h2><p>gRPC is designed for server-to-server communication, not for connecting browsers to servers. Browser JavaScript can&rsquo;t make gRPC calls directly, even though most browsers support HTTP/2.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/http-2-protocol.png?sfvrsn=502b958c_2" title="HTTP/2 protocol" alt="HTTP/2 protocol" /></p><p>JavaScript running in a browser doesn&rsquo;t control which HTTP protocol is used. It relies on wrapper APIs like fetch and XHR, which abstract away the underlying protocol, and the browser manages that internally.</p><p>There are packages like grpc-web that let you call gRPC servers from the web, but they work around this limitation. They make HTTP/1 requests to a proxy server (like Envoy) that you set up, which then converts those requests to HTTP/2 and calls the target gRPC server.</p><p>In short, JavaScript running in a client application in the browser can&rsquo;t make gRPC calls directly because it can&rsquo;t control which HTTP protocol gets used, and gRPC requires HTTP/2.</p><h2 id="what-well-be-building">What We&rsquo;ll Be Building</h2><p>We&rsquo;ll build a simple movie listing application that performs basic CRUD operations on movies. We&rsquo;ll use Protocol Buffers to define the API contract, since it&rsquo;s gRPC&rsquo;s default serialization mechanism.</p><p>Here&rsquo;s what we&rsquo;ll do:</p><ul><li>Define the API contract using Protocol Buffers</li><li>Set up a NestJS server that implements the contract methods</li><li>Connect to the server using grpcurl</li><li>Connect from a .NET application</li></ul><h2 id="steps-to-set-up-a-grpc-server-and-connect-a-client">Steps to Set Up a gRPC Server and Connect a Client</h2><p>Now that we understand what we&rsquo;re building, here are the steps we&rsquo;ll follow:</p><ul><li><strong>Define the API Contract:</strong> We&rsquo;ll introduce Protocol Buffers as gRPC&rsquo;s interface definition and serialization engine. Then we&rsquo;ll create proto files that define the services and methods the server will implement and clients will call.</li><li><strong>Create the Server:</strong> We&rsquo;ll use the proto files to generate a server stub for NestJS. This is code we&rsquo;ll use to implement the service methods. We&rsquo;ll cover static and dynamic proto file parsing, and learn about protoc (the Protocol Buffer compiler) and language-specific plugins.</li><li><strong>Create Clients:</strong> We&rsquo;ll build clients to interact with the server. We&rsquo;ll expose server documentation using the Reflection API and demo a simple interaction between server and client.</li><li><strong>Add Authentication:</strong> We&rsquo;ll show how clients can authenticate at the channel level using SSL credentials or at the function level using metadata.</li></ul><h2 id="protocol-buffers-and-proto-files">Protocol Buffers and Proto Files</h2><p>Protocol Buffers (protobuf) is the default way to define the API contract in gRPC. You use it to define services, methods and messages in files with the <code>.proto</code> extension. Protobuf handles encoding and decoding of messages sent between client and server over the channel.</p><p>The tool that compiles proto files is called protoc. Since protobuf is language-neutral, you can use protoc with <code>.proto</code> files to generate stubs in any programming language. A stub is just generated code that mirrors the contract defined in the <code>.proto</code> file, ready for you to implement on the server or call from the client.</p><p>When protoc generates a stub at build time, it&rsquo;s called static parsing. However, you can also dynamically parse <code>.proto</code> files using community or native packages without generating a stub. This means you don&rsquo;t need to install protoc.</p><p>Some of the benefits of dynamic parsing is faster development with fewer tools and configurations. The trade-off is less type hinting when developing.</p><p>Since proto files define the API contract, they&rsquo;re usually shared across projects. Typically, they&rsquo;re stored in a separate repository and imported via a submodule. For this guide, we&rsquo;ll define them once and manually copy them to each project.</p><h2 id="defining-a-proto-file">Defining a Proto File</h2><p>Create a file called <code>movie_service.proto</code> in your preferred directory and add the following to it:</p><pre class=" language-protobuf"><code class="prism  language-protobuf">edition <span class="token operator">=</span><span class="token string">"2023"</span><span class="token punctuation">;</span>

<span class="token keyword">package</span> movie<span class="token punctuation">;</span>

service MovieService <span class="token punctuation">{</span>
  rpc <span class="token function">ListMovies</span> <span class="token punctuation">(</span>ListMoviesRequest<span class="token punctuation">)</span> <span class="token function">returns</span> <span class="token punctuation">(</span>MediaList<span class="token punctuation">)</span><span class="token punctuation">;</span>
  rpc <span class="token function">StreamMovies</span> <span class="token punctuation">(</span>ListMoviesRequest<span class="token punctuation">)</span> <span class="token function">returns</span> <span class="token punctuation">(</span>stream MediaItem<span class="token punctuation">)</span><span class="token punctuation">;</span>
  rpc <span class="token function">SearchMovies</span> <span class="token punctuation">(</span>FindMovieRequest<span class="token punctuation">)</span> <span class="token function">returns</span> <span class="token punctuation">(</span>MediaItem<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">message</span> ListMoviesRequest <span class="token punctuation">{</span><span class="token punctuation">}</span>

<span class="token keyword">message</span> FindMovieRequest <span class="token punctuation">{</span>
  <span class="token primitive symbol">uint32</span> id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">message</span> MediaItem <span class="token punctuation">{</span>
  <span class="token primitive symbol">string</span> title <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">string</span> type <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">string</span> genre <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">string</span> poster <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">string</span> released <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">float</span> imdb_rating <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">;</span>
  <span class="token builtin">repeated</span> <span class="token primitive symbol">string</span> images <span class="token operator">=</span> <span class="token number">7</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">uint32</span> id <span class="token operator">=</span> <span class="token number">8</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">message</span> MediaList <span class="token punctuation">{</span>
  <span class="token builtin">repeated</span> MediaItem items <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>We defined a simple proto file following standard conventions. Proto file names should be in <code>lower_snake_case</code>. The file starts by specifying the 2023 edition. Editions are the modern approach; older versions used <code>syntax = "proto2"</code> or <code>syntax = "proto3"</code>.</p><p>Next, we define the package name <code>movie</code>. Think of the package name as a namespace where all messages and services declared here belong to the &ldquo;movie&rdquo; package. So the full reference to <code>MovieService</code> is <code>movie.MovieService</code>.</p><p>A proto file can have multiple services and messages. Message and service names should be in <code>TitleCase</code>. We have four message types and one service.</p><p>Our <code>MovieService</code> has three RPC methods: <code>ListMovies</code>, <code>StreamMovies</code> and <code>SearchMovies</code>. Every RPC method takes an input message and returns an output message. The package, service and method names form the endpoint the client calls.</p><p>For example, to call <code>ListMovies</code>, the endpoint is:</p><p><code>&lt;server-url&gt;/movie.MovieService/ListMovies</code></p><p>To understand these RPC methods and the communication patterns they support, let&rsquo;s look at the four communication patterns gRPC supports.</p><h2 id="communication-patterns-in-grpc">Communication Patterns in gRPC</h2><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/commmunication-patterns-in-grpc.png?sfvrsn=7a90ddf6_2" title="Commmunication patterns in gRPC" alt="Commmunication patterns in gRPC" /></p><p>gRPC&rsquo;s communication patterns (or streaming models) are abstractions that represent streams of data sent between client and server over HTTP/2. Streaming is possible because of HTTP/2&rsquo;s multiplexing capability.</p><p>In Unary streaming, the client sends a request and the server sends back a response, like a regular HTTP/1 REST API call. <code>ListMovies</code> uses this pattern.</p><p>In server streaming, the client sends a request and the server streams data back. Use this when the server needs to send large amounts of data in chunks. <code>StreamMovies</code> uses this pattern.</p><p>In client streaming, the client streams data to the server by sending it in chunks and receives a single response. Use this when the client has large payloads to send.</p><p>In bidirectional streaming, both client and server stream data simultaneously in real time. Think of this like WebSockets, but strictly for server-to-server communication.</p><p>The choice of communication pattern depends on several factors, such as the volume of messages, induced latency and communication frequency.</p><p>We also defined message types, which represent the payload sent over the network. Each field has a type, name and field number.</p><p>For example, in <code>string poster = 4;</code>:</p><ul><li><code>string</code> is the field type (any Protocol Buffers supported type)</li><li><code>poster</code> is the field name</li><li><code>4</code> is the field number</li></ul><p>The field name (<code>poster</code>) is arbitrary. You choose it as long as it&rsquo;s not a keyword and is in <code>snake_case</code>. This name is only for developers to identify the field; it doesn&rsquo;t affect how data is sent over the network.</p><p>The field number (<code>4</code>) identifies the field when encoded and sent over the network. In the 2023 edition, field numbers range from 1 to 536,870,111, excluding 19,000&ndash;19,999 (reserved). Each field number must be unique within its message.</p><p>Cardinality defines how many values a field can hold:</p><ul><li>Single value: Holds one string, e.g., <code>string released = 5;</code></li><li>Multiple values: Holds an array of strings, e.g., <code>repeated string images = 7;</code></li></ul><p>Protobuf also supports Maps.</p><p>Fields can also be scalar or composite. Scalar fields (like <code>string released = 5;</code>) are primitives that can&rsquo;t be decomposed further. Composite fields use custom types (other messages or enums).</p><p>For example:</p><pre class=" language-js"><code class="prism  language-js">message MediaList <span class="token punctuation">{</span>
  repeated MediaItem items <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>Here, <code>items</code> is a multi-valued composite field of type <code>MediaItem</code>.</p><h2 id="setting-up-the-grpc-server">Setting Up the gRPC Server</h2><p>Now let&rsquo;s set up the server using the <code>movie_service.proto</code> file. gRPC is supported by many programming languages. We&rsquo;ll use TypeScript and build a NestJS microservice for its elegant architecture and developer-friendly approach.</p><p>Assuming you have the NestJS CLI installed, open your terminal and run the following command to set up the project:</p><pre class=" language-shell"><code class="prism  language-shell">nest new grpc-movie-app
cd grpc-movie-app
npm i --save @nestjs/microservices @grpc/grpc-js @grpc/proto-loader
</code></pre><p>We set up a NestJS project called <code>grpc-movie-app</code> and installed three key dependencies:</p><ul><li><code>@nestjs/microservices</code> &ndash; NestJS&rsquo;s microservices framework for building microservices</li><li><code>@grpc/grpc-js</code> &ndash; gRPC implementation for JavaScript and TypeScript</li><li><code>@grpc/proto-loader</code> &ndash; Dynamically loads and parses proto files at runtime</li></ul><h2 id="adding-the-proto-files">Adding the Proto Files</h2><p>Now, let&rsquo;s move the proto files to a folder within our project. In the <code>grpc-movie-app</code> folder, run these commands:</p><pre class=" language-shell"><code class="prism  language-shell">cd src
mkdir proto
cp &lt;PATH-TO-PROTO-FILE&gt;/movie_service.proto ./proto
</code></pre><p>The command above creates a folder called <code>proto</code> within the <code>./src</code> directory of our NestJS app and copies our <code>movie_service.proto</code> file to it.</p><h2 id="setting-up-the-nestjs-grpc-microservice">Setting Up the NestJS gRPC Microservice</h2><p>Update your <code>main.ts</code> file with the following:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> NestFactory <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/core'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> AppModule <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./app.module'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> MicroserviceOptions<span class="token punctuation">,</span> Transport <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/microservices'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> join <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'path'</span><span class="token punctuation">;</span>

<span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token keyword">await</span> NestFactory<span class="token punctuation">.</span>createMicroservice<span class="token operator">&lt;</span>MicroserviceOptions<span class="token operator">&gt;</span><span class="token punctuation">(</span>
    AppModule<span class="token punctuation">,</span>
    <span class="token punctuation">{</span>
      transport<span class="token punctuation">:</span> Transport<span class="token punctuation">.</span>GRPC<span class="token punctuation">,</span>
      options<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token keyword">package</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'movie'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
        protoPath<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token function">join</span><span class="token punctuation">(</span>__dirname<span class="token punctuation">,</span> <span class="token string">'/proto/movie_service.proto'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
        url<span class="token punctuation">:</span> <span class="token string">'localhost:4190'</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">await</span> app<span class="token punctuation">.</span><span class="token function">listen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>In the code above, we configured the microservice using <code>createMicroservice()</code>. The second parameter is the configuration object that specifies what kind of microservice to create. We set <code>transport: Transport.GRPC</code> to use gRPC, then passed the options object to configure our gRPC service.</p><p>Our service listens on port 4190. Using the <code>protoPath</code> option, we can specify as many proto files as we want to implement in our service. In our case, we only specified one, <code>movie_service.proto</code>. The <code>package</code> option allows us to specify which packages within these files we want to implement.</p><p>NestJS internally validates the file paths and proto file contents for correctness. Syntax errors or missing package names throw appropriate errors.</p><p>For example, if we had specified a non-existent package name like <code>moviell</code> and started our application by running <code>npm run start:dev</code>, we&rsquo;d see an error like:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/errors-non-existent-packages.png?sfvrsn=361f4f4a_2" title="Errors thrown when non-existent packages are added" alt="Errors thrown when non-existent packages are added" /></p><h2 id="a-note-on-dynamic-parsing">A Note on Dynamic Parsing</h2><p>Notice that our NestJS application can work with proto files and validate them without installing protoc. The <code>@grpc/proto-loader</code> package dynamically parses <code>.proto</code> files at runtime, which provides a smooth developer experience and makes gRPC integration easy.</p><h3 id="optional-improving-type-safety-with-ts-proto">Optional: Improving Type Safety with ts-proto</h3><p>To improve type safety and ease contract implementation, we can use ts-proto, a protoc plugin. Protoc (the protobuf compiler) doesn&rsquo;t natively support JavaScript/TypeScript, which is why plugins like ts-proto exist. It generates interfaces for services and messages, provides type safety and catches compile-time errors when working with proto files. This is helpful when dynamically parsing <code>.proto</code> files.</p><p>To use ts-proto, first install protoc. Open your terminal and run the following command:</p><pre class=" language-shell"><code class="prism  language-shell">brew install protobuf
</code></pre><p>Next, run the following command to install ts-proto in your <code>grpc-movie-app</code> folder:</p><pre class=" language-shell"><code class="prism  language-shell">npm i ts-proto
</code></pre><p>Then update your <code>package.json</code> to add a script that uses protoc with the ts-proto plugin:</p><pre class=" language-js"><code class="prism  language-js"><span class="token string">"scripts"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
  <span class="token string">"compile:proto"</span><span class="token punctuation">:</span> <span class="token string">"protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=. --ts_proto_opt=nestJs=true,addGrpcMetadata=true,addNestjsRestParameter=true ./src/proto/movie_service.proto"</span>
<span class="token punctuation">}</span>
</code></pre><p>In the code above, we added a script called <code>compile:proto</code> that tells protoc to use the ts-proto plugin on <code>movie_service.proto</code> and generate TypeScript output in the same directory as the proto file.</p><p>Since ts-proto is framework-agnostic, we need to configure it for NestJS. We do this with the <code>--ts_proto_opt</code> option, which accepts a comma-separated list of options. We set <code>nestJs=true</code> to target NestJS, and <code>addGrpcMetadata=true</code> and <code>addNestjsRestParameter=true</code> to include metadata and rest parameters the generated interfaces, as shown in the sample snippet below:</p><pre class=" language-protobuf"><code class="prism  language-protobuf"><span class="token function">listMovies</span><span class="token punctuation">(</span>
  request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span>
  metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>rest<span class="token punctuation">:</span> any
<span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> Observable<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> MediaList<span class="token punctuation">;</span>
</code></pre><p>Now, running <code>npm run compile:proto</code> will generate a new <code>movie_service.ts</code> file in the <code>proto</code> folder with the generated TypeScript interfaces as shown below.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/movie-service-file.png?sfvrsn=d4e856f4_2" title="Newly generated movie_service.ts file" alt="Newly generated movie_service.ts file" /></p><p>Let&rsquo;s preview the contents of the generated <code>movie_service.ts</code> file incrementally. It generates variables for the package name and TypeScript types for the respective messages.</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token keyword">type</span> <span class="token punctuation">{</span> Metadata <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@grpc/grpc-js"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> GrpcMethod<span class="token punctuation">,</span> GrpcStreamMethod <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"@nestjs/microservices"</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> Observable <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"rxjs"</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> protobufPackage <span class="token operator">=</span> <span class="token string">"movie"</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">ListMoviesRequest</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">FindMovieRequest</span> <span class="token punctuation">{</span>
  id<span class="token punctuation">:</span> <span class="token keyword">number</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">MediaItem</span> <span class="token punctuation">{</span>
  title<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  <span class="token keyword">type</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  genre<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  poster<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  released<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
  imdbRating<span class="token punctuation">:</span> <span class="token keyword">number</span><span class="token punctuation">;</span>
  images<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  id<span class="token punctuation">:</span> <span class="token keyword">number</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">MediaList</span> <span class="token punctuation">{</span>
  items<span class="token punctuation">:</span> MediaItem<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> MOVIE_PACKAGE_NAME <span class="token operator">=</span> <span class="token string">"movie"</span><span class="token punctuation">;</span>
</code></pre><p>It also generates the client interface with the MovieService methods for calling the gRPC server. We won&rsquo;t be needing this though.</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">MovieServiceClient</span> <span class="token punctuation">{</span>
  <span class="token function">listMovies</span><span class="token punctuation">(</span>request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span> metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span> <span class="token operator">...</span>rest<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Observable<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span><span class="token punctuation">;</span>
  <span class="token function">streamMovies</span><span class="token punctuation">(</span>request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span> metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span> <span class="token operator">...</span>rest<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span><span class="token punctuation">;</span>
  <span class="token function">searchMovies</span><span class="token punctuation">(</span>request<span class="token punctuation">:</span> FindMovieRequest<span class="token punctuation">,</span> metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span> <span class="token operator">...</span>rest<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>The generated file also includes a server-side interface called <code>MovieServiceController</code> that we&rsquo;ll implement. It also generates a decorator called <code>MovieServiceControllerMethods()</code> that binds the method names to the <code>GrpcMethod()</code> function, automatically registering them as request handlers.</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">export</span> <span class="token keyword">interface</span> <span class="token class-name">MovieServiceController</span> <span class="token punctuation">{</span>
  <span class="token function">listMovies</span><span class="token punctuation">(</span>
    request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span>
    metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span>
    <span class="token operator">...</span>rest<span class="token punctuation">:</span> <span class="token keyword">any</span>
  <span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> Observable<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> MediaList<span class="token punctuation">;</span>
  <span class="token function">streamMovies</span><span class="token punctuation">(</span>request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span> metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span> <span class="token operator">...</span>rest<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span><span class="token punctuation">;</span>
  <span class="token function">searchMovies</span><span class="token punctuation">(</span>
    request<span class="token punctuation">:</span> FindMovieRequest<span class="token punctuation">,</span>
    metadata<span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span>
    <span class="token operator">...</span>rest<span class="token punctuation">:</span> <span class="token keyword">any</span>
  <span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span> <span class="token operator">|</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span> <span class="token operator">|</span> MediaItem<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">MovieServiceControllerMethods</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token keyword">constructor</span><span class="token punctuation">:</span> <span class="token keyword">Function</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> grpcMethods<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">"listMovies"</span><span class="token punctuation">,</span> <span class="token string">"streamMovies"</span><span class="token punctuation">,</span> <span class="token string">"searchMovies"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">const</span> method <span class="token keyword">of</span> grpcMethods<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> descriptor<span class="token punctuation">:</span> <span class="token keyword">any</span> <span class="token operator">=</span> Reflect<span class="token punctuation">.</span><span class="token function">getOwnPropertyDescriptor</span><span class="token punctuation">(</span><span class="token keyword">constructor</span><span class="token punctuation">.</span>prototype<span class="token punctuation">,</span> method<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token function">GrpcMethod</span><span class="token punctuation">(</span><span class="token string">"MovieService"</span><span class="token punctuation">,</span> method<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">constructor</span><span class="token punctuation">.</span>prototype<span class="token punctuation">[</span>method<span class="token punctuation">]</span><span class="token punctuation">,</span> method<span class="token punctuation">,</span> descriptor<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">const</span> grpcStreamMethods<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">const</span> method <span class="token keyword">of</span> grpcStreamMethods<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> descriptor<span class="token punctuation">:</span> <span class="token keyword">any</span> <span class="token operator">=</span> Reflect<span class="token punctuation">.</span><span class="token function">getOwnPropertyDescriptor</span><span class="token punctuation">(</span><span class="token keyword">constructor</span><span class="token punctuation">.</span>prototype<span class="token punctuation">,</span> method<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token function">GrpcStreamMethod</span><span class="token punctuation">(</span><span class="token string">"MovieService"</span><span class="token punctuation">,</span> method<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">constructor</span><span class="token punctuation">.</span>prototype<span class="token punctuation">[</span>method<span class="token punctuation">]</span><span class="token punctuation">,</span> method<span class="token punctuation">,</span> descriptor<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">const</span> MOVIE_SERVICE_NAME <span class="token operator">=</span> <span class="token string">"MovieService"</span><span class="token punctuation">;</span>
</code></pre><p>Notice that method and class variable names follow TypeScript conventions. For example, <code>ListMovies</code> in the proto file becomes <code>listMovies</code> in TypeScript.</p><h2 id="implementing-contract-methods">Implementing Contract Methods</h2><p>First, let&rsquo;s add some dummy movie data. Create a file called <code>media-data.json</code> in the <code>src</code> folder and add the following to it:</p><pre class=" language-js"><code class="prism  language-js"><span class="token punctuation">[</span>
  <span class="token punctuation">{</span>
    <span class="token string">"id"</span><span class="token punctuation">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
    <span class="token string">"title"</span><span class="token punctuation">:</span> <span class="token string">"Avatar"</span><span class="token punctuation">,</span>
    <span class="token string">"type"</span><span class="token punctuation">:</span> <span class="token string">"movie"</span><span class="token punctuation">,</span>
    <span class="token string">"genre"</span><span class="token punctuation">:</span> <span class="token string">"Action, Adventure, Fantasy"</span><span class="token punctuation">,</span>
    <span class="token string">"poster"</span><span class="token punctuation">:</span> <span class="token string">"http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg"</span><span class="token punctuation">,</span>
    <span class="token string">"released"</span><span class="token punctuation">:</span> <span class="token string">"18 Dec 2009"</span><span class="token punctuation">,</span>
    <span class="token string">"imdbRating"</span><span class="token punctuation">:</span> <span class="token number">7.9</span><span class="token punctuation">,</span>
    <span class="token string">"images"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMjEyOTYyMzUxNl5BMl5BanBnXkFtZTcwNTg0MTUzNA@@._V1_SX1500_CR0,0,1500,999_AL_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BNzM2MDk3MTcyMV5BMl5BanBnXkFtZTcwNjg0MTUzNA@@._V1_SX1777_CR0,0,1777,999_AL_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTY2ODQ3NjMyMl5BMl5BanBnXkFtZTcwODg0MTUzNA@@._V1_SX1777_CR0,0,1777,999_AL_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxOTEwNDcxN15BMl5BanBnXkFtZTcwOTg0MTUzNA@@._V1_SX1777_CR0,0,1777,999_AL_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTYxMDg1Nzk1MV5BMl5BanBnXkFtZTcwMDk0MTUzNA@@._V1_SX1500_CR0,0,1500,999_AL_.jpg"</span>
    <span class="token punctuation">]</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span>
    <span class="token string">"id"</span><span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
    <span class="token string">"title"</span><span class="token punctuation">:</span> <span class="token string">"I Am Legend"</span><span class="token punctuation">,</span>
    <span class="token string">"type"</span><span class="token punctuation">:</span> <span class="token string">"movie"</span><span class="token punctuation">,</span>
    <span class="token string">"genre"</span><span class="token punctuation">:</span> <span class="token string">"Drama, Horror, Sci-Fi"</span><span class="token punctuation">,</span>
    <span class="token string">"poster"</span><span class="token punctuation">:</span> <span class="token string">"https://m.media-amazon.com/images/M/MV5BMGE1OWZkZmItNmVhMC00YzAxLTgxOTctNjg3NWExM2RmOWJkXkEyXkFqcGc@._V1_.jpg"</span><span class="token punctuation">,</span>
    <span class="token string">"released"</span><span class="token punctuation">:</span> <span class="token string">"14 Dec 2007"</span><span class="token punctuation">,</span>
    <span class="token string">"imdbRating"</span><span class="token punctuation">:</span> <span class="token number">7.2</span><span class="token punctuation">,</span>
    <span class="token string">"images"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTI0NTI4NjE3NV5BMl5BanBnXkFtZTYwMDA0Nzc4._V1_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTIwMDg2MDU4M15BMl5BanBnXkFtZTYwMTA0Nzc4._V1_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTc5MDM1OTU5OV5BMl5BanBnXkFtZTYwMjA0Nzc4._V1_.jpg"</span><span class="token punctuation">,</span>
      <span class="token string">"https://images-na.ssl-images-amazon.com/images/M/MV5BMTA0MTI2NjMzMzFeQTJeQWpwZ15BbWU2MDMwNDc3OA@@._V1_.jpg"</span>
    <span class="token punctuation">]</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">]</span>
</code></pre><p>Now create a controller to implement the contract methods:</p><pre class=" language-shell"><code class="prism  language-shell">nest g co movie
</code></pre><p>The command above generates a <code>movie.controller.ts</code> file in a <code>movie</code> folder. Update its content with the following:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Controller <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/common'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> <span class="token keyword">from</span><span class="token punctuation">,</span> Observable <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'rxjs'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> movies <span class="token keyword">from</span> <span class="token string">'../media-data.json'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>
  FindMovieRequest<span class="token punctuation">,</span>
  ListMoviesRequest<span class="token punctuation">,</span>
  MediaItem<span class="token punctuation">,</span>
  MediaList<span class="token punctuation">,</span>
  MovieServiceController<span class="token punctuation">,</span>
  MovieServiceControllerMethods<span class="token punctuation">,</span>
<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'src/proto/movie_service'</span><span class="token punctuation">;</span>

@<span class="token function">Controller</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
@<span class="token function">MovieServiceControllerMethods</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">MovieController</span> <span class="token keyword">implements</span> <span class="token class-name">MovieServiceController</span> <span class="token punctuation">{</span>
  <span class="token function">listMovies</span><span class="token punctuation">(</span>request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> Observable<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> MediaList <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span> items<span class="token punctuation">:</span> movies <span class="token keyword">as</span> MediaItem<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token function">streamMovies</span><span class="token punctuation">(</span>request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">)</span><span class="token punctuation">:</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">from</span><span class="token punctuation">(</span>movies<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token function">searchMovies</span><span class="token punctuation">(</span>
    request<span class="token punctuation">:</span> FindMovieRequest<span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span> <span class="token operator">|</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span> <span class="token operator">|</span> MediaItem <span class="token punctuation">{</span>
    <span class="token keyword">const</span> defaultItem<span class="token punctuation">:</span> MediaItem <span class="token operator">=</span> <span class="token punctuation">{</span>
      id<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
      title<span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
      <span class="token keyword">type</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
      genre<span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
      poster<span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
      released<span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span>
      imdbRating<span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
      images<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span>movies <span class="token keyword">as</span> MediaItem<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token punctuation">(</span>m<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> m<span class="token punctuation">.</span>id <span class="token operator">===</span> request<span class="token punctuation">.</span>id<span class="token punctuation">)</span> <span class="token operator">||</span> defaultItem<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>Some key imports in this snippet above include our dummy data from <code>media-data.json</code>, the decorators and interfaces generated by ts-proto in <code>movie_service.ts</code> when we ran the <code>compile:proto</code> script, and utilities from RxJS for streaming data.</p><p>The <code>MovieServiceControllerMethods()</code> decorator internally registers all methods of the <code>MovieController</code> class as gRPC request handlers. The method names map to those defined in the <code>movie</code> package from <code>movie_service.proto</code>. Notice that method names are in <code>camelCase</code>, not <code>TitleCase</code> as they were in the proto file.</p><p>For server streaming methods like <code>streamMovies</code> that return large amounts of data, we use an Observable. This lets the client consume the data in chunks without overwhelming the network. When we test, we&rsquo;ll see how the client handles streaming data compared to sending everything at once.</p><p>Every gRPC method must return data matching its return type (assuming no errors). Notice that in <code>searchMovies</code>, we return an empty <code>MediaItem</code> instance as a default when no movie is found.</p><h2 id="setting-up-the-client">Setting Up the Client</h2><p>gRPC is supported by many programming languages, so we can set up a client or server in our preferred language. There are also GUI tools like <a href="https://www.telerik.com/fiddler/fiddler-everywhere" target="_blank">Progress Telerik Fiddler Everywhere</a>, plus command-line tools for testing gRPC servers.</p><p>In this section, we&rsquo;ll create clients using two approaches: grpcurl from the terminal and a .NET console application.</p><h3 id="using-grpcurl">Using grpcurl</h3><p>grpcurl is a command-line tool similar to curl, but designed for testing gRPC servers.</p><p>First, let&rsquo;s install grpcurl. On macOS, use homebrew:</p><pre class=" language-shell"><code class="prism  language-shell">brew install grpcurl
</code></pre><p>Make sure the NestJS gRPC server is running:</p><pre class=" language-shell"><code class="prism  language-shell">npm run start:dev
</code></pre><h2 id="calling-the-grpc-server">Calling the gRPC Server</h2><p>Open your terminal and run the following command:</p><pre class=" language-shell"><code class="prism  language-shell">grpcurl -plaintext -proto ./src/proto/movie_service.proto localhost:4190 movie.MovieService/ListMovies
</code></pre><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/triggering-the-listmovie-method.png?sfvrsn=4fe4290f_2" title="Triggering the ListMovie method" alt="Triggering the ListMovie method" /></p><p>The command above connects to the NestJS gRPC server on <code>localhost:4190</code> and triggers the <code>ListMovies</code> function by specifying <code>movie.MovieService/ListMovies</code>. The output is displayed in the terminal.</p><p>The <code>-plaintext</code> option tells grpcurl not to perform a TLS handshake since the server doesn&rsquo;t have an SSL certificate. The <code>-proto</code> option specifies the path to the API contract. Finally, we specify which method to call using <code>movie.MovieService/ListMovies</code>.</p><p>Now, let&rsquo;s trigger the <code>SearchMovies</code> function:</p><pre class=" language-shell"><code class="prism  language-shell">grpcurl -plaintext -proto ./src/proto/movie_service.proto -d '{"id": 1}' localhost:4190 movie.MovieService/SearchMovies
</code></pre><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/triggering-the-searchmovie-method.png?sfvrsn=7ff1a43f_2" title="Triggering the SearchMovie method" alt="Triggering the SearchMovie method" /></p><p>For functions that require parameters, use the <code>-d</code> option to pass the data.</p><h2 id="exposing-grpc-api-using-reflection">Exposing gRPC API Using Reflection</h2><p>Notice that calling the server without passing the contract throws an error.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/without-reflection-api.png?sfvrsn=bc7f3814_2" title="Error when calling the server without Reflection API enabled" alt="Error when calling the server without Reflection API enabled" /></p><p>The Reflection protocol allows gRPC servers to expose their API contract to clients, similar to how Swagger documentation works for REST APIs. This is useful when debugging because clients can get a list of services and methods exposed by the server and automatically download the <code>.proto</code> file.</p><p>Let&rsquo;s update our server to enable Reflection:</p><h2 id="adding-reflection-to-our-nestjs-grpc-server">Adding Reflection to Our NestJS gRPC Server</h2><p>Open your terminal and run the following command to install the Reflection package:</p><pre class=" language-shell"><code class="prism  language-shell">npm i --save @grpc/reflection
</code></pre><p>Next, update the <code>main.ts</code> file with the following:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> NestFactory <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/core'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> AppModule <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'./app.module'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> MicroserviceOptions<span class="token punctuation">,</span> Transport <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/microservices'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> join <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'path'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> ReflectionService <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@grpc/reflection'</span><span class="token punctuation">;</span>

<span class="token keyword">async</span> <span class="token keyword">function</span> <span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token keyword">await</span> NestFactory<span class="token punctuation">.</span>createMicroservice<span class="token operator">&lt;</span>MicroserviceOptions<span class="token operator">&gt;</span><span class="token punctuation">(</span>
    AppModule<span class="token punctuation">,</span>
    <span class="token punctuation">{</span>
      transport<span class="token punctuation">:</span> Transport<span class="token punctuation">.</span>GRPC<span class="token punctuation">,</span>
      options<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token keyword">package</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'movie'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
        protoPath<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token function">join</span><span class="token punctuation">(</span>__dirname<span class="token punctuation">,</span> <span class="token string">'/proto/movie_service.proto'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
        url<span class="token punctuation">:</span> <span class="token string">'localhost:4190'</span><span class="token punctuation">,</span>
        onLoadPackageDefinition<span class="token punctuation">:</span> <span class="token punctuation">(</span>pkg<span class="token punctuation">,</span> server<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
          <span class="token keyword">new</span> <span class="token class-name">ReflectionService</span><span class="token punctuation">(</span>pkg<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addToServer</span><span class="token punctuation">(</span>server<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">await</span> app<span class="token punctuation">.</span><span class="token function">listen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token function">bootstrap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>We updated our code to include the <code>onLoadPackageDefinition</code> callback, which receives a function. This function is called for each parsed package defined in the <code>package</code> array. After the proto loader parses the <code>.proto</code> file and generates the service definitions for each package, an object is passed that looks like this:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/structure-of-a-parsed-proto-file.png?sfvrsn=198fd182_2" title="Structure of a parsed proto file" alt="Structure of a parsed proto file" /></p><p>The object is then passed to the <code>ReflectionService</code> and exposed to clients. To see this in action, let&rsquo;s restart the server and use grpcurl to interact with it:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/grpcurl-successfully-calls-searchmovies.png?sfvrsn=22f8f2b1_2" title="grpcurl successfully calls SearchMovies via the Reflection API" alt="grpcurl successfully calls SearchMovies via the Reflection API" /></p><p>With Reflection enabled, notice that we can now interact with the server without explicitly passing the <code>.proto</code> file.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/discovering-the-movieservice.png?sfvrsn=17f1fe1_2" title="Discovering the MovieService and downloading proto files using grpcurl with Reflection" alt="Discovering the MovieService and downloading proto files using grpcurl with Reflection" /></p><p>We can use the <code>list</code> command to see the services implemented by the gRPC server. Use the <code>describe</code> command to see the RPC methods exposed by that service. With the <code>-proto-out-dir</code> option, you can download the <code>.proto</code> files from the server. In the following command, we download them to a folder called <code>output_protos</code> that was created automatically for us.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/automatically-created-folder.png?sfvrsn=a8875177_2" title="Automatically created folder" alt="Automatically created folder" /></p><h2 id="adding-a-.net-client">Adding a .NET Client</h2><p>We will also be creating a small dotnet client to interface with our server. Assuming you have the <a target="_blank" href="https://learn.microsoft.com/en-us/dotnet/core/tutorials/create-console-app?pivots=vscode">.NET SDK</a> installed, open your terminal and run the following command to create a basic console application:</p><pre class=" language-shell"><code class="prism  language-shell">dotnet new console -n GrpcMovieClient
cd GrpcMovieClient
mkdir Protos
cp &lt;PATH-TO-PROTO-FILE&gt;/movie_service.proto ./Protos/MovieService.proto
dotnet add GrpcMovieClient.csproj package Grpc.Net.Client
dotnet add GrpcMovieClient.csproj package Google.Protobuf
dotnet add GrpcMovieClient.csproj package Grpc.Tools
</code></pre><p>The commands above create a console application in a folder called <code>GrpcMovieClient</code> and navigate into it. Then we create a <code>Protos</code> folder and copy <code>movie_service.proto</code> to it as <code>MovieService.proto</code>, following standard C# naming conventions.</p><p>Finally, we install three dependencies: <code>Grpc.Net.Client</code> for making gRPC calls, <code>Google.Protobuf</code> for working with protobuf messages, and <code>Grpc.Tools</code> (optional) for generating the client stub. Alternatively, you can use protoc directly to generate the stub.</p><p>Next, let&rsquo;s update the <code>GrpcMovieClient.csproj</code> file to include the proto file:</p><pre class=" language-csproj"><code class="prism  language-csproj">&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
  &lt;PropertyGroup&gt;
    &lt;OutputType&gt;Exe&lt;/OutputType&gt;
    &lt;TargetFramework&gt;net10.0&lt;/TargetFramework&gt;
    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
  &lt;/PropertyGroup&gt;

  &lt;ItemGroup&gt;
    &lt;PackageReference Include="Google.Protobuf" Version="3.35.1" /&gt;
    &lt;PackageReference Include="Grpc.Net.Client" Version="2.83.0" /&gt;
    &lt;PackageReference Include="Grpc.Tools" Version="2.83.0"&gt;
      &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
      &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
    &lt;/PackageReference&gt;
  &lt;/ItemGroup&gt;

  &lt;ItemGroup&gt;
    &lt;Protobuf Include="Protos/MovieService.proto" GrpcServices="Client" /&gt;
  &lt;/ItemGroup&gt;
&lt;/Project&gt;
</code></pre><p>The <code>&lt;Protobuf&gt;</code> element tells the build system to generate a gRPC client from <code>MovieService.proto</code>. The <code>GrpcServices="Client"</code> attribute specifies that we want client stubs, not server stubs.</p><p>Build the project:</p><pre class=" language-shell"><code class="prism  language-shell">dotnet build
</code></pre><p>This command builds all dependencies. <code>Grpc.Tools</code> automatically generates a <code>Protos</code> folder in the <code>obj/Debug/net10.0</code> directory containing the generated client stubs from the proto file.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/generated-protos-folder.png?sfvrsn=182fbc6d_2" title="Generated protos folder" alt="Generated protos folder" /></p><p>The build generates a <code>MovieService.cs</code> file containing the code needed for the client to call the gRPC server.</p><p>Now let&rsquo;s update the <code>program.cs</code> file with the following:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">using</span> Grpc<span class="token punctuation">.</span>Core<span class="token punctuation">;</span>
<span class="token keyword">using</span> Grpc<span class="token punctuation">.</span>Net<span class="token punctuation">.</span>Client<span class="token punctuation">;</span>
<span class="token keyword">using</span> Movie<span class="token punctuation">;</span>

<span class="token keyword">using</span> <span class="token keyword">var</span> channel <span class="token operator">=</span> GrpcChannel<span class="token punctuation">.</span><span class="token function">ForAddress</span><span class="token punctuation">(</span><span class="token string">"http://localhost:4190"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> client <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MovieService<span class="token punctuation">.</span>MovieServiceClient</span><span class="token punctuation">(</span>channel<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// List all movies</span>
<span class="token keyword">var</span> reply <span class="token operator">=</span> <span class="token keyword">await</span> client<span class="token punctuation">.</span><span class="token function">ListMoviesAsync</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ListMoviesRequest</span> <span class="token punctuation">{</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> indentedJson <span class="token operator">=</span> System<span class="token punctuation">.</span>Text<span class="token punctuation">.</span>Json<span class="token punctuation">.</span>JsonSerializer<span class="token punctuation">.</span><span class="token function">Serialize</span><span class="token punctuation">(</span>
  reply<span class="token punctuation">,</span>
  <span class="token keyword">new</span> <span class="token class-name">System<span class="token punctuation">.</span>Text<span class="token punctuation">.</span>Json<span class="token punctuation">.</span>JsonSerializerOptions</span> <span class="token punctuation">{</span> WriteIndented <span class="token operator">=</span> <span class="token keyword">true</span> <span class="token punctuation">}</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span>indentedJson<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// Search for a movie by ID</span>
<span class="token keyword">var</span> searchReply <span class="token operator">=</span> <span class="token keyword">await</span> client<span class="token punctuation">.</span><span class="token function">SearchMoviesAsync</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">FindMovieRequest</span> <span class="token punctuation">{</span> Id <span class="token operator">=</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span>System<span class="token punctuation">.</span>Text<span class="token punctuation">.</span>Json<span class="token punctuation">.</span>JsonSerializer<span class="token punctuation">.</span><span class="token function">Serialize</span><span class="token punctuation">(</span>
  searchReply<span class="token punctuation">,</span>
  <span class="token keyword">new</span> <span class="token class-name">System<span class="token punctuation">.</span>Text<span class="token punctuation">.</span>Json<span class="token punctuation">.</span>JsonSerializerOptions</span> <span class="token punctuation">{</span> WriteIndented <span class="token operator">=</span> <span class="token keyword">true</span> <span class="token punctuation">}</span>
<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// Stream movies</span>
<span class="token keyword">var</span> streamCall <span class="token operator">=</span> client<span class="token punctuation">.</span><span class="token function">StreamMovies</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ListMoviesRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">await</span> <span class="token keyword">foreach</span> <span class="token punctuation">(</span>MediaItem item <span class="token keyword">in</span> streamCall<span class="token punctuation">.</span>ResponseStream<span class="token punctuation">.</span><span class="token function">ReadAllAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span>item<span class="token punctuation">.</span>Title<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>In the code above, we start by importing namespaces, which include the gRPC core library, the client connection setup library and the generated stub.</p><p>Next, we create a connection to the server and bind it to <code>MovieService</code>. It&rsquo;s a best practice to share one connection among multiple clients in gRPC rather than creating a new connection for each client.</p><p>We then call each method of the <code>MovieService</code> and print the output. The code shows how calling <code>ListMovies</code> (returns all movies), <code>SearchMovies</code> (finds a specific movie) and <code>StreamMovies</code> (streams movies one at a time).</p><p>To run the application:</p><pre class=" language-shell"><code class="prism  language-shell">dotnet run
</code></pre><h2 id="using-metadata">Using Metadata</h2><p>Metadata (or headers) in gRPC are key-value pairs that clients include in requests or servers include in responses. Common uses include adding authentication and authorization information, or storing information that would otherwise bloat the protobuf message body.</p><p>Let&rsquo;s see how to add metadata on the server and read it from the client. Update the <code>streamMovies</code> method in your <code>movie.controller.ts</code> file to look like so:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Metadata<span class="token punctuation">,</span> ServerUnaryCall<span class="token punctuation">,</span> status <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@grpc/grpc-js'</span><span class="token punctuation">;</span>

@<span class="token function">Controller</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
@<span class="token function">MovieServiceControllerMethods</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">MovieController</span> <span class="token keyword">implements</span> <span class="token class-name">MovieServiceController</span> <span class="token punctuation">{</span>
  <span class="token function">streamMovies</span><span class="token punctuation">(</span>
    request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span>
    metadata<span class="token operator">?</span><span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span>
    call<span class="token operator">?</span><span class="token punctuation">:</span> ServerUnaryCall<span class="token operator">&lt;</span><span class="token keyword">any</span><span class="token punctuation">,</span> <span class="token keyword">any</span><span class="token operator">&gt;</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">:</span> Observable<span class="token operator">&lt;</span>MediaItem<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> meta <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Metadata</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    meta<span class="token punctuation">.</span><span class="token keyword">set</span><span class="token punctuation">(</span><span class="token string">'token'</span><span class="token punctuation">,</span> <span class="token string">'secret-token'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    call<span class="token operator">?</span><span class="token punctuation">.</span><span class="token function">sendMetadata</span><span class="token punctuation">(</span>meta<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token keyword">from</span><span class="token punctuation">(</span>movies<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// ... other code</span>
<span class="token punctuation">}</span>
</code></pre><p>Every gRPC method receives three parameters. The second represents metadata sent by the client. Since we want to send metadata back to the client, we imported the <code>Metadata</code> class and created an instance. We added a key-value pair (<code>token</code>: <code>secret-token</code>) using the <code>set()</code> method. The <code>Metadata</code> instance has methods to add, update, and retrieve entries.</p><p>Now let&rsquo;s update the .NET client to read and display the returned metadata. Update the <code>program.cs</code> file to match the following:</p><pre class=" language-csharp"><code class="prism  language-csharp"><span class="token keyword">var</span> streamCall <span class="token operator">=</span> client<span class="token punctuation">.</span><span class="token function">StreamMovies</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ListMoviesRequest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> headers <span class="token operator">=</span> <span class="token keyword">await</span> streamCall<span class="token punctuation">.</span>ResponseHeadersAsync<span class="token punctuation">;</span>

Console<span class="token punctuation">.</span><span class="token function">WriteLine</span><span class="token punctuation">(</span>headers<span class="token punctuation">.</span><span class="token function">GetValue</span><span class="token punctuation">(</span><span class="token string">"token"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>Run <code>dotnet run</code> to see the output:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/net-metadata-token.png?sfvrsn=92415f90_2" title=".net metadata token from the server" alt=".net metadata token from the serverr" /></p><p>Similarly, running the command using grpcurl, we get the header shown below.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/grpcurl-metadata-token.png?sfvrsn=eb545eba_2" title="grpcurl metadata token from the server" alt="grpcurl metadata token from the server" /></p><p>We included the <code>-v</code> (verbose) option to get the full response details. Notice the <code>token</code> header in the response.</p><h2 id="a-sneak-peek-at-the-wire-format">A Sneak Peek at the Wire Format</h2><p>We&rsquo;ve successfully created a gRPC server and connected clients using grpcurl and the .NET framework. Earlier, we emphasized protocol buffers&rsquo; role in encoding and decoding messages. In this section, we will cover the wire format and how messages are encoded before being sent over the network.</p><p>For example, when we call <code>SearchMovies</code> with a <code>FindMovieRequest</code> payload, the message looks like this:</p><pre class=" language-protobuf"><code class="prism  language-protobuf"><span class="token keyword">message</span> FindMovieRequest <span class="token punctuation">{</span>
  <span class="token primitive symbol">uint32</span> id <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>A message can have multiple fields. Here&rsquo;s how it&rsquo;s encoded and sent over the wire after the client and server establish a connection:</p><p>Field order doesn&rsquo;t matter during encoding or decoding. However, it&rsquo;s important to use lower field numbers (1&ndash;15) whenever possible, as they take up less space on the wire.</p><p>Like protobuf itself, the wire format defines wire types, which are type definitions used to encode messages and their fields.</p><p>Each message is encoded as a map where the keys are field numbers paired with the wire type, and the values are the assigned values. For example, if we set <code>id=30</code>, in protoscope format (a user-friendly way to view encoded messages), it looks like <code>1:VARINT 30</code> or simply <code>1: 30</code>. Protoscope can infer the type automatically. The wire type tells parsers how much data to expect.</p><p>The binary format doesn&rsquo;t capture field names, so they don&rsquo;t affect encoding. For example, the field name <code>id</code> isn&rsquo;t included when the message is encoded. After decoding, the recipient uses the <code>.proto</code> file to infer the field names.</p><h2 id="known-client-limits">Known Client Limits</h2><p>Clients have a fixed limit of about 4MB per response. If the data exceeds this limit, you should stream it instead. To see this in action, we&rsquo;ll update the <code>media-data.json</code> file to include more movies, bumping the file size to 7.3MB.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/increased-file-size.png?sfvrsn=bf9dde96_2" title="Increased file size" alt="Increased file size" /></p><p>When we trigger the <code>listMovies</code> function, the server tries to return all the data. Since it exceeds the 4MB limit, we get an error when we run <code>dotnet run</code>:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/dotnet-error.png?sfvrsn=f259b745_2" title="dotnet error" alt="dotnet error" /></p><p>Using grpcurl, we get a similar error:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/grpcurl-error.png?sfvrsn=6b4f9e09_2" title="grpcurl error" alt="grpcurl error" /></p><p>However, when we call <code>StreamMovies</code>, the data is sent in chunks so that we can retrieve all of it without errors.</p><h2 id="error-handling">Error Handling</h2><p>Handling errors is key to building reliable gRPC servers and applications. API Improvement Proposals (AIP)-193 defines how gRPC errors should be propagated. An error should take the following form:</p><pre class=" language-protobuf"><code class="prism  language-protobuf"><span class="token comment">// The Status type defines a logical error model suitable for different</span>
<span class="token comment">// programming languages and environments.</span>
<span class="token keyword">message</span> Status <span class="token punctuation">{</span>
  <span class="token primitive symbol">int32</span> code <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">string</span> <span class="token keyword">message</span> <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
  <span class="token builtin">repeated</span> google<span class="token punctuation">.</span>protobuf<span class="token punctuation">.</span>Any details <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>Here&rsquo;s a sample gRPC error with its key properties:</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/sample-grpc-error.png?sfvrsn=9b7f4a01_2" title="Sample gRPC error" alt="Sample gRPC error" /></p><p>The <code>Status</code> message type defines how gRPC errors should be structured. The <code>code</code> field is an integer enum representing one of gRPC&rsquo;s standard error codes. For example, code 8 means RESOURCE_EXHAUSTED. The <code>message</code> field provides a developer-friendly explanation of the error. The <code>details</code> field holds additional structured information about the error to communicate to the client.</p><p>Standard properties include:</p><pre class=" language-protobuf"><code class="prism  language-protobuf"><span class="token keyword">message</span> ErrorInfo <span class="token punctuation">{</span>
  <span class="token primitive symbol">string</span> reason <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
  <span class="token primitive symbol">string</span> domain <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
  map<span class="token operator">&lt;</span><span class="token primitive symbol">string</span><span class="token punctuation">,</span> <span class="token primitive symbol">string</span><span class="token operator">&gt;</span> metadata <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><p>Handling errors is as straightforward as wrapping our code in a try-catch block. Let&rsquo;s update the <code>ListMovies</code> function to throw an error:</p><pre class=" language-ts"><code class="prism  language-ts"><span class="token keyword">import</span> <span class="token punctuation">{</span> Metadata<span class="token punctuation">,</span> ServerUnaryCall<span class="token punctuation">,</span> status <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@grpc/grpc-js'</span><span class="token punctuation">;</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span> RpcException <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'@nestjs/microservices'</span><span class="token punctuation">;</span>

@<span class="token function">Controller</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
@<span class="token function">MovieServiceControllerMethods</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">export</span> <span class="token keyword">class</span> <span class="token class-name">MovieController</span> <span class="token keyword">implements</span> <span class="token class-name">MovieServiceController</span> <span class="token punctuation">{</span>
  <span class="token comment">// ... other code</span>

  <span class="token function">listMovies</span><span class="token punctuation">(</span>
    request<span class="token punctuation">:</span> ListMoviesRequest<span class="token punctuation">,</span>
    metadata<span class="token operator">?</span><span class="token punctuation">:</span> Metadata<span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">:</span> Promise<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> Observable<span class="token operator">&lt;</span>MediaList<span class="token operator">&gt;</span> <span class="token operator">|</span> MediaList <span class="token punctuation">{</span>
    <span class="token keyword">try</span> <span class="token punctuation">{</span>
      <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RpcException</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        code<span class="token punctuation">:</span> status<span class="token punctuation">.</span>NOT_FOUND<span class="token punctuation">,</span>
        message<span class="token punctuation">:</span> <span class="token string">'Movies not found'</span><span class="token punctuation">,</span>
        details<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          reason<span class="token punctuation">:</span> <span class="token string">'MOVIES_NOT_AVAILABLE'</span><span class="token punctuation">,</span>
          domain<span class="token punctuation">:</span> <span class="token string">'movie-service'</span><span class="token punctuation">,</span>
          metadata<span class="token punctuation">:</span> <span class="token punctuation">{</span>
            someKey<span class="token punctuation">:</span> <span class="token string">'somevalue'</span><span class="token punctuation">,</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">throw</span> error<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><p>We imported two key classes: <code>status</code> holds the different gRPC error codes, and <code>RpcException</code> is NestJS&rsquo;s standard class for throwing RPC errors. We then updated the code to throw an error. To see the output, run grpcurl.</p><h2 id="authentication">Authentication</h2><p>So far, our gRPC server and client have communicated over an insecure channel, and the client can call any function. While this works during development, production requires secure authentication. Like regular web servers, gRPC has two levels of authentication: channel level and call level.</p><p>Channel-level security uses SSL/TLS credentials to encrypt data in transit. For TLS certificates signed by a Certificate Authority (e.g., Sectigo, DigiCert, Let&rsquo;s Encrypt), no client changes are needed. For self-signed certificates, you need to create certificates for both client and server, plus a root certificate.</p><h3 id="call-level">Call Level</h3><p>Call-level authentication uses headers/metadata to authorize individual function calls. Popular options include plain JWTs and Google OAuth (which only applies to Google services).</p><h2 id="conclusion">Conclusion</h2><p>This guide covers everything you need to build and connect to gRPC servers so you can build fast, type-safe microservices that scale. gRPC eliminates much of the complexity that comes with REST APIs, and with what we&rsquo;ve covered in this article, you can confidently implement distributed systems that communicate reliably across languages and platforms.</p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">Why Chat Is Not the Future of AI UX</h4></div><div class="col-8">When people interact with <a target="_blank" href="https://www.telerik.com/blogs/why-chat-not-future-ai-ux">AI capabilities in a product, chat is only one surface option</a>, and it&rsquo;s not always the right choice. Let&rsquo;s explore other options.<p>&nbsp;</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17513937.gif" height="1" width="1"/>]]></content>
  </entry>
  <entry>
    <id>urn:uuid:afbf36f9-d153-4c04-887e-18a542b6b877</id>
    <title type="text">Explore Helix DB Graph-Vector Database</title>
    <summary type="text">Let’s create a simple todo knowledge graph  with the type-safe HelixDB TypeScript package and run some test queries.</summary>
    <published>2026-10-30T13:49:47Z</published>
    <updated>2026-11-30T00:42:24Z</updated>
    <author>
      <name>Jonathan Gamble </name>
    </author>
    <link rel="alternate" href="https://feeds.telerik.com/link/10827/17511475/explore-helix-db-graph-vector-database"/>
    <content type="text"><![CDATA[<p><span class="featured">Let&rsquo;s create a simple todo knowledge graph  with the type-safe HelixDB TypeScript package and run some test queries.</span></p><p><a target="_blank" href="https://www.helix-db.com/">HelixDB</a> is wonderful database for graphs, vectors and objects. I am HUGE fan of graph databases, as I believe joins just make things complicated. In graph databases, all nodes, edges and properties are first-class citizens. You query directly by the location, not joining them.</p><h2 id="tldr">TL;DR</h2><p>Creating a simple todo knowledge graph is easy with the HelixDB TypeScript package. It does not use <a target="_blank" href="https://www.gqlstandards.org/">GQL Standard Language</a> or <a target="_blank" href="https://neo4j.com/product/cypher-graph-query-language/">Cypher</a>, but its own <a target="_blank" href="https://github.com/HelixDB/helix-ql-docs">HelixQL</a> language.</p><p>Here we create and test queries for a todo app, and the database is type-safe by default. The TS package allows for complex queries without manually adding more query strings. You can also host on <a target="_blank" href="https://www.helix-db.com/">Helix Cloud</a> for auto scaling applications.</p><h2 id="install-helix">Install Helix</h2><p>For these tests, we are going to just use the basic in-memory Helix.</p><h3 id="install-cli">Install CLI</h3><pre class=" language-bash"><code class="prism  language-bash">curl -sSL <span class="token string">"https://install.helix-db.com"</span> <span class="token operator">|</span> <span class="token function">bash</span>
</code></pre><p>Create a folder and initialize it.</p><pre class=" language-bash"><code class="prism  language-bash">helix init local --name dev
</code></pre><p>Start Helix.</p><pre class=" language-bash"><code class="prism  language-bash">helix start dev
</code></pre><ul><li>This create an in-memory version. See <a target="_blank" href="https://docs.helix-db.com/database/local-development">installation</a> for disk local development.</li></ul><p> In Windows, you need to update your ENV path for <code>helix</code> to work standalone.</p><ol><li>Search for &ldquo;Environment Variables.&rdquo;</li><li>Open System Properties.</li><li>Make sure <code>C:\Users\YOUR USER\.local\bin</code> is added to your path. This could be different depending on your default settings.</li></ol><p>⚠️ Remember to stop the dev server when you&rsquo;re done.</p><pre class=" language-bash"><code class="prism  language-bash">helix dev stop
</code></pre><ul><li>Our local connection is at <code>http://localhost:6969</code>.</li></ul><h3 id="install-helix-ts-packages">Install Helix TS Packages</h3><pre class=" language-bash"><code class="prism  language-bash"><span class="token function">npm</span> i @helix-db/helix-db
<span class="token function">npm</span> i -D vitest
</code></pre><ul><li>We use <code>vitest</code> for testing.</li></ul><p>Our <code>package.json</code> should have test scripts as well.</p><pre class=" language-bash"><code class="prism  language-bash"><span class="token punctuation">{</span>
  <span class="token string">"type"</span><span class="token keyword">:</span> <span class="token string">"module"</span>,
  <span class="token string">"dependencies"</span><span class="token keyword">:</span> <span class="token punctuation">{</span>
    <span class="token string">"@helix-db/helix-db"</span><span class="token keyword">:</span> <span class="token string">"^2.0.5"</span>
  <span class="token punctuation">}</span>,
  <span class="token string">"devDependencies"</span><span class="token keyword">:</span> <span class="token punctuation">{</span>
    <span class="token string">"vitest"</span><span class="token keyword">:</span> <span class="token string">"^4.1.9"</span>
  <span class="token punctuation">}</span>,
  <span class="token string">"scripts"</span><span class="token keyword">:</span> <span class="token punctuation">{</span>
    <span class="token string">"test"</span><span class="token keyword">:</span> <span class="token string">"vitest run"</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><h2 id="create-our-test-queries">Create Our Test Queries</h2><p>With a basic <em>Todo App</em>, we want to CRUD a user record and CRUD a todo record.</p><pre class=" language-tsx"><code class="prism  language-tsx">import {
NodeRef,
Predicate,
PropertyInput,
PropertyProjection,
defineParams,
defineQueries,
g,
param,
readBatch,
registerRead,
registerWrite,
writeBatch
} from '@helix-db/helix-db';

const userParams = defineParams({
name: param.string()
});

const userIdParams = defineParams({
id: param.i64()
});

const todoParams = defineParams({
title: param.string()
});

const todoIdParams = defineParams({
id: param.i64()
});

const addTodoParams = defineParams({
title: param.string(),
createdBy: param.string()
});

const todosByUserParams = defineParams({
createdBy: param.string()
});

const addUser = registerWrite(
() =&gt;
writeBatch()
.varAs(
'user',
g()
.addN('User', {
name: PropertyInput.param('name')
})
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('name')
])
)
.returning(['user']),
userParams
);

const findUser = registerRead(
() =&gt;
readBatch()
.varAs(
'user',
g()
.nWithLabel('User')
.where(Predicate.eqParam('name', 'name'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('name')
])
)
.returning(['user']),
userParams
);

const getUserById = registerRead(
() =&gt;
readBatch()
.varAs(
'user',
g()
.n(NodeRef.param('id'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('name')
])
)
.returning(['user']),
userIdParams
);

const deleteUser = registerWrite(
() =&gt;
writeBatch()
.varAs(
'user',
g()
.nWithLabel('User')
.where(Predicate.eqParam('name', 'name'))
.drop()
)
.returning(['user']),
userParams
);

const addTodo = registerWrite(
() =&gt;
writeBatch()
.varAs(
'todo',
g()
.addN('Todo', {
title: PropertyInput.param('title'),
createdBy: PropertyInput.param('createdBy'),
completed: false
})
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
addTodoParams
);

const findTodo = registerRead(
() =&gt;
readBatch()
.varAs(
'todo',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('title', 'title'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
todoParams
);

const getTodoById = registerRead(
() =&gt;
readBatch()
.varAs(
'todo',
g()
.n(NodeRef.param('id'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
todoIdParams
);

const getTodosByUser = registerRead(
() =&gt;
readBatch()
.varAs(
'todos',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('createdBy', 'createdBy'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todos']),
todosByUserParams
);

const completeTodo = registerWrite(
() =&gt;
writeBatch()
.varAs(
'todo',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('title', 'title'))
.setProperty('completed', true)
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
todoParams
);

const deleteTodo = registerWrite(
() =&gt;
writeBatch()
.varAs(
'todo',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('title', 'title'))
.drop()
)
.returning(['todo']),
todoParams
);

export const queries = defineQueries({
read: {
findUser,
getUserById,
findTodo,
getTodoById,
getTodosByUser
},
write: {
addUser,
deleteUser,
addTodo,
completeTodo,
deleteTodo
}
});
</code></pre><h2 id="creating-breakdown">Creating Breakdown</h2><p><strong>Add a User</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const addUser = registerWrite(
() =&gt;
writeBatch()
.varAs(
'user',
g()
.addN('User', {
name: PropertyInput.param('name')
})
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('name')
])
)
.returning(['user']),
userParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">QUERY addUser<span class="token punctuation">(</span>name: String<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    <span class="token keyword">user</span> <span class="token operator">&lt;</span><span class="token operator">-</span> AddN<span class="token operator">&lt;</span><span class="token keyword">User</span><span class="token operator">&gt;</span><span class="token punctuation">(</span>{
        name: name
    }<span class="token punctuation">)</span>::{
        id: ID<span class="token punctuation">,</span>
        name: name
    }

    <span class="token keyword">RETURN</span> <span class="token keyword">user</span>
</code></pre><p><strong>Add a Todo</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const addTodo = registerWrite(
() =&gt;
writeBatch()
.varAs(
'todo',
g()
.addN('Todo', {
title: PropertyInput.param('title'),
createdBy: PropertyInput.param('createdBy'),
completed: false
})
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
addTodoParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">QUERY addTodo<span class="token punctuation">(</span>title: String<span class="token punctuation">,</span> createdBy: String<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    todo <span class="token operator">&lt;</span><span class="token operator">-</span> AddN<span class="token operator">&lt;</span>Todo<span class="token operator">&gt;</span><span class="token punctuation">(</span>{
        title: title<span class="token punctuation">,</span>
        createdBy: createdBy<span class="token punctuation">,</span>
        completed: <span class="token boolean">false</span>
    }<span class="token punctuation">)</span>::{
        id: ID<span class="token punctuation">,</span>
        title: title<span class="token punctuation">,</span>
        createdBy: createdBy<span class="token punctuation">,</span>
        completed: completed
    }

    <span class="token keyword">RETURN</span> todo
</code></pre><ul><li><code>varAs</code> tells it what node to use.</li><li><code>addN</code> means create.</li><li><code>PropertyInput.param</code> uses the parameters in the query for safety.</li><li><code>project</code> passes the variables in.</li><li><code>PropertyProjection</code> tells it what to actual call the variable. The <code>$id</code> is the ID, a special case.</li></ul><p> I find the queries to be easy to use and learn.</p><h2 id="reading-breakdown">Reading Breakdown</h2><p><strong>Get a User</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const findUser = registerRead(
() =&gt;
readBatch()
.varAs(
'user',
g()
.nWithLabel('User')
.where(Predicate.eqParam('name', 'name'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('name')
])
)
.returning(['user']),
userParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">QUERY findUser<span class="token punctuation">(</span>name: String<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    <span class="token keyword">user</span> <span class="token operator">&lt;</span><span class="token operator">-</span> N<span class="token operator">&lt;</span><span class="token keyword">User</span><span class="token operator">&gt;</span>
        ::<span class="token keyword">WHERE</span><span class="token punctuation">(</span>_::name <span class="token operator">=</span><span class="token operator">=</span> name<span class="token punctuation">)</span>
        ::{ id: ID<span class="token punctuation">,</span> name: name }

    <span class="token keyword">RETURN</span> <span class="token keyword">user</span>
</code></pre><p><strong>Get a User By ID</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const getUserById = registerRead(
() =&gt;
readBatch()
.varAs(
'user',
g()
.n(NodeRef.param('id'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('name')
])
)
.returning(['user']),
userIdParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">QUERY getUserById<span class="token punctuation">(</span>id: ID<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    <span class="token keyword">user</span> <span class="token operator">&lt;</span><span class="token operator">-</span> N<span class="token operator">&lt;</span>id<span class="token operator">&gt;</span>::{
        id: ID<span class="token punctuation">,</span>
        name: name
    }

    <span class="token keyword">RETURN</span> <span class="token keyword">user</span>
</code></pre><p><strong>Get a Todo</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const findTodo = registerRead(
() =&gt;
readBatch()
.varAs(
'todo',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('title', 'title'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
todoParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">QUERY findTodo<span class="token punctuation">(</span>title: String<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    todo <span class="token operator">&lt;</span><span class="token operator">-</span> N<span class="token operator">&lt;</span>Todo<span class="token operator">&gt;</span>
        ::<span class="token keyword">WHERE</span><span class="token punctuation">(</span>_::title <span class="token operator">=</span><span class="token operator">=</span> title<span class="token punctuation">)</span>
        ::{
            id: ID<span class="token punctuation">,</span>
            title: title<span class="token punctuation">,</span>
            createdBy: createdBy<span class="token punctuation">,</span>
            completed: completed
        }

    <span class="token keyword">RETURN</span> todo
</code></pre><p><strong>Get a Todo By ID</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const getTodoById = registerRead(
() =&gt;
readBatch()
.varAs(
'todo',
g()
.n(NodeRef.param('id'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
todoIdParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">
QUERY getTodoById<span class="token punctuation">(</span>id: ID<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    todo <span class="token operator">&lt;</span><span class="token operator">-</span> N<span class="token operator">&lt;</span>id<span class="token operator">&gt;</span>::{
        id: ID<span class="token punctuation">,</span>
        title: title<span class="token punctuation">,</span>
        createdBy: createdBy<span class="token punctuation">,</span>
        completed: completed
    }

    <span class="token keyword">RETURN</span> todo
</code></pre><p><strong>Get Todo By User</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const getTodosByUser = registerRead(
() =&gt;
readBatch()
.varAs(
'todos',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('createdBy', 'createdBy'))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todos']),
todosByUserParams
);
</code></pre><p>Compiles to:</p><pre class=" language-tsx"><code class="prism  language-tsx">QUERY getTodosByUser(createdBy: String) =&gt;
    todos &lt;- N&lt;Todo&gt;
        ::WHERE(_::createdBy == createdBy)
        ::{
            id: ID,
            title: title,
            createdBy: createdBy,
            completed: completed
        }

    RETURN todos
</code></pre><ul><li><code>nWithLabel</code> determines an alias.</li><li><code>Predicate.eqParam</code> can create <em>WHERE</em> clauses easily.</li><li><code>n</code> is used with <code>NodeRef.param('id')</code> for ID <em>WHERE</em> clauses.</li></ul><h2 id="update-breakdown">Update Breakdown</h2><p><strong>Update a Todo</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const completeTodo = registerWrite(
() =&gt;
writeBatch()
.varAs(
'todo',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('title', 'title'))
.setProperty('completed', true)
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.returning(['todo']),
todoParams
);
</code></pre><p>Compiles to:</p><pre class=" language-tsx"><code class="prism  language-tsx">QUERY completeTodo(title: String) =&gt;
    todo &lt;- N&lt;Todo&gt;
        ::WHERE(_::title == title)
        ::UPDATE({
            completed: true
        })
        ::{
            id: ID,
            title: title,
            createdBy: createdBy,
            completed: completed
        }

    RETURN todo
</code></pre><ul><li><code>setProperty</code> is used for updates instead of <code>addN</code>.</li></ul><h3 id="delete-breakdown">Delete Breakdown</h3><p><strong>Delete a User</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const deleteUser = registerWrite(
() =&gt;
writeBatch()
.varAs(
'user',
g()
.nWithLabel('User')
.where(Predicate.eqParam('name', 'name'))
.drop()
)
.returning(['user']),
userParams
);
</code></pre><p>Compiles to:</p><pre class=" language-sql"><code class="prism  language-sql">QUERY deleteUser<span class="token punctuation">(</span>name: String<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>
    <span class="token keyword">user</span> <span class="token operator">&lt;</span><span class="token operator">-</span> N<span class="token operator">&lt;</span><span class="token keyword">User</span><span class="token operator">&gt;</span>
        ::<span class="token keyword">WHERE</span><span class="token punctuation">(</span>_::name <span class="token operator">=</span><span class="token operator">=</span> name<span class="token punctuation">)</span>
        ::<span class="token keyword">DROP</span>

    <span class="token keyword">RETURN</span> <span class="token keyword">user</span>
</code></pre><p><strong>Delete a Todo</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const deleteTodo = registerWrite(
() =&gt;
writeBatch()
.varAs(
'todo',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('title', 'title'))
.drop()
)
.returning(['todo']),
todoParams
);
</code></pre><p>Compiles to:</p><pre class=" language-tsx"><code class="prism  language-tsx">QUERY deleteTodo(title: String) =&gt;
    todo &lt;- N&lt;Todo&gt;
        ::WHERE(_::title == title)
        ::DROP

    RETURN todo
</code></pre><ul><li><code>drop</code> is delete.</li></ul><h2 id="special-functions">Special Functions</h2><pre class=" language-tsx"><code class="prism  language-tsx">const userParams = defineParams({
name: param.string()
});

const userIdParams = defineParams({
id: param.i64()
});

const todoParams = defineParams({
title: param.string()
});

const todoIdParams = defineParams({
id: param.i64()
});

const addTodoParams = defineParams({
title: param.string(),
createdBy: param.string()
});

const todosByUserParams = defineParams({
createdBy: param.string()
});
</code></pre><ul><li>We can define our parameters to functions with <code>defineParams</code>.</li></ul><pre class=" language-tsx"><code class="prism  language-tsx">export const queries = defineQueries({
read: {
findUser,
getUserById,
findTodo,
getTodoById,
getTodosByUser
},
write: {
addUser,
deleteUser,
addTodo,
completeTodo,
deleteTodo
}
});
</code></pre><ul><li>These keep our queries type safe with <code>defineQueries</code>.</li></ul><h2 id="running-our-queries">Running Our Queries</h2><p>Let&rsquo;s create a <code>vitest</code> test file in the <code>scripts</code> folder called <code>helix.test.ts</code>.</p><pre class=" language-tsx"><code class="prism  language-tsx">import { Client } from '@helix-db/helix-db';
import { describe, expect, it } from 'vitest';
import { queries } from './queries';

const client = new Client('http://localhost:6969');

const user = {
name: 'Jonathan'
};

const todos = [
{
title: 'Buy groceries',
createdBy: user.name
},
{
title: 'Wash the car',
createdBy: user.name
}
];

type Result&lt;T&gt; = {
properties: T[];
};

type User = {
id: number;
name: string;
};

type Todo = {
id: number;
title: string;
createdBy: string;
completed: boolean;
};

let userId: number;
let lastTodoId: number;

describe('HelixDB', () =&gt; {
it('adds a user', async () =&gt; {
const result = await client
.query&lt;{ user: Result&lt;User&gt; }&gt;()
.dynamic(queries.call.addUser(user))
.send();

expect(result.user.properties[0]?.name).toBe(user.name);

userId = result.user.properties[0]!.id;
});

it('gets the user by name', async () =&gt; {
const result = await client
.query&lt;{ user: Result&lt;User&gt; }&gt;()
.dynamic(queries.call.findUser(user))
.send();

expect(result.user.properties).toContainEqual({
id: userId,
name: user.name
});
});

it('adds two todos', async () =&gt; {
const first = await client
.query&lt;{ todo: Result&lt;Todo&gt; }&gt;()
.dynamic(queries.call.addTodo(todos[0]))
.send();

const second = await client
.query&lt;{ todo: Result&lt;Todo&gt; }&gt;()
.dynamic(queries.call.addTodo(todos[1]))
.send();

expect(first.todo.properties[0]?.title).toBe(todos[0].title);
expect(second.todo.properties[0]?.title).toBe(todos[1].title);

lastTodoId = second.todo.properties[0]!.id;
});

it('gets the last todo by ID', async () =&gt; {
const result = await client
.query&lt;{ todo: Result&lt;Todo&gt; }&gt;()
.dynamic(queries.call.getTodoById({ id: lastTodoId }))
.send();

expect(result.todo.properties[0]).toEqual({
id: lastTodoId,
title: todos[1].title,
createdBy: user.name,
completed: false
});
});

it('gets all todos by user', async () =&gt; {
const result = await client
.query&lt;{ todos: Result&lt;Todo&gt; }&gt;()
.dynamic(
queries.call.getTodosByUser({
createdBy: user.name
})
)
.send();

expect(result.todos.properties).toHaveLength(2);

expect(result.todos.properties).toEqual(
expect.arrayContaining([
expect.objectContaining(todos[0]),
expect.objectContaining(todos[1])
])
);
});

it('deletes the todos', async () =&gt; {
await client
.query()
.dynamic(
queries.call.deleteTodo({
title: todos[0].title
})
)
.send();

await client
.query()
.dynamic(
queries.call.deleteTodo({
title: todos[1].title
})
)
.send();

const result = await client
.query&lt;{ todos: Result&lt;Todo&gt; }&gt;()
.dynamic(
queries.call.getTodosByUser({
createdBy: user.name
})
)
.send();

expect(result.todos.properties).toEqual([]);
});

it('deletes the user', async () =&gt; {
await client
.query()
.dynamic(queries.call.deleteUser(user))
.send();

const result = await client
.query&lt;{ user: Result&lt;User&gt; }&gt;()
.dynamic(queries.call.findUser(user))
.send();

expect(result.user.properties).toEqual([]);
});
});
</code></pre><p>We run our queries with:</p><pre class=" language-tsx"><code class="prism  language-tsx">// Connect
const client = new Client('http://localhost:6969');

// Query
const result = await client
.query&lt;RETURN_TYPE&gt;()
.dynamic(queries.call[QUERY_NAME](QUERY_PARAMS))
.send();

// returns
// "result.TYPE"
</code></pre><p> And it is type-safe!!!</p><h2 id="bonus-complex-queries">Bonus: Complex Queries</h2><p>I generated some more complex queries to see what is possible.</p><p><strong>Get Todos by User with Count</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const getTodosByUserWithCount = registerRead(
() =&gt;
readBatch()
.varAs(
'todos',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('createdBy', 'createdBy'))
.skip(StreamBound.expr(Expr.param('offset')))
.limit(StreamBound.expr(Expr.param('limit')))
.project([
PropertyProjection.renamed('$id', 'id'),
PropertyProjection.new('title'),
PropertyProjection.new('createdBy'),
PropertyProjection.new('completed')
])
)
.varAs(
'count',
g()
.nWithLabel('Todo')
.where(Predicate.eqParam('createdBy', 'createdBy'))
.count()
)
.returning(['todos', 'count']),
todosByUserWithCountParams
);
</code></pre><ul><li>We can return a count with pagination!</li><li><code>offset</code> and <code>limit</code> are there for us!</li><li>Multiple <code>varAs</code> allow for multiple queries in one.</li></ul><p><strong>Fuzzy Search</strong></p><pre class=" language-tsx"><code class="prism  language-tsx">const noParams = defineParams({});

// Need index to search

const createUserNameTextIndex = registerWrite(
    () =&gt;
        writeBatch()
            .varAs(
                'index',
                g().createTextIndexNodes('User', 'name', null)
            )
            .returning(['index']),
    noParams
);

const fuzzyUserParams = defineParams({
    query: param.string(),
    limit: param.i64()
});

const findUsersFuzzy = registerRead(
    () =&gt;
        readBatch()
            .varAs(
                'users',
                g()
                    .textSearchNodesWith(
                        'User',
                        'name',
                        PropertyInput.param('query'),
                        StreamBound.expr(Expr.param('limit')),
                        null
                    )
                    .project([
                        PropertyProjection.renamed('$id', 'id'),
                        PropertyProjection.new('name'),
                        PropertyProjection.renamed('$distance', 'score')
                    ])
            )
            .returning(['users']),
    fuzzyUserParams
);
</code></pre><ul><li>We must first create an index for fuzzy search like any other database.</li><li>We <code>textSearchNodesWith</code> for matching.</li></ul><p> These queries show up a little slower in testing because individual queries are sent to the server one by one. But in a real-world app you could just run one batch of queries with multiple <code>varAs</code>.</p><p><img src="https://www.telerik.com/sfimages/default-source/blogs/2026/2026-10/helix-test.png?sfvrsn=51f93749_2" alt="Helix test run" /></p><h2 id="helix-cloud">Helix Cloud</h2><p>If you love the database like I do, and you want to use it in production, you can host on <a target="_blank" href="https://www.helix-db.com/">Helix Cloud</a>. Not only does it auto-scale on demand, which is awesome, it is robust, highly available, and extremely fast.</p><h3 id="final-verdict">Final Verdict</h3><p>I&rsquo;m super impressed with Helix. I like graph databases that could be used for regular apps or more complex use cases. There is no need to host five databases for one app (unless you&rsquo;re a tech giant!). And yes, this supports vectors for AI, as all databases should.</p><p><strong>More Graph Databases</strong></p><ul><li><a target="_blank" href="https://www.telerik.com/blogs/typedb-graph-database-things">TypeDB</a></li><li><a target="_blank" href="https://www.telerik.com/blogs/graph-database-future-surrealdb">SurrealDB</a></li><li><a target="_blank" href="https://www.telerik.com/blogs/introduction-edgedb">Gel / EdgeDB</a> (now open-source only)</li></ul><p><strong>Repo:</strong> <a target="_blank" href="https://github.com/jdgamble555/my-helix-app">GitHub</a></p><aside><hr data-sf-ec-immutable="" /><div class="row"><div class="col-4 u-normal-full u-small-mb0"><h4 class="u-fs20 u-fw5 u-lh125 u-mb0">Pure Surreal Database Authentication in Nuxt</h4></div><div class="col-8"><p class="u-fs16 u-mb0"><a target="_blank" href="http://www.telerik.com/blogs/pure-surreal-database-authentication-nuxt">See how Nuxt pairs up with Surreal Database</a> with a sample app enabling login, register, logout and password change options with route guards and server-safe APIs.</p></div></div></aside><img src="https://feeds.telerik.com/link/10827/17511475.gif" height="1" width="1"/>]]></content>
  </entry>
</feed>
