<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jade Gu</title>
    <description>The latest articles on DEV Community by Jade Gu (@lucifier129).</description>
    <link>https://dev.to/lucifier129</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F549747%2F37150569-01d1-40fd-b196-e9fd0a08fee9.jpeg</url>
      <title>DEV Community: Jade Gu</title>
      <link>https://dev.to/lucifier129</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucifier129"/>
    <language>en</language>
    <item>
      <title>Farrow: A new web framework in the new year</title>
      <dc:creator>Jade Gu</dc:creator>
      <pubDate>Fri, 01 Jan 2021 13:28:59 +0000</pubDate>
      <link>https://dev.to/lucifier129/farrow-a-new-web-framework-in-the-new-year-1l47</link>
      <guid>https://dev.to/lucifier129/farrow-a-new-web-framework-in-the-new-year-1l47</guid>
      <description>&lt;p&gt;Today I'd like to introduce you to a new project I've recently developed - &lt;a href="https://github.com/Lucifier129/farrow"&gt;Farrow&lt;/a&gt;. a type-friendly functional style Node.js web framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;In the current Node.js open source ecosystem, there are already expressjs, koajs, hapi, restify, fastify, nestjs, and perhaps countless other web services frameworks, so do we need another one?&lt;/p&gt;

&lt;p&gt;The answer may vary from person to person, so I'd like to share my personal opinion here.&lt;/p&gt;

&lt;p&gt;Most of the popular web service frameworks in Node.js were developed with a JavaScript perspective before TypeScript became really popular.&lt;/p&gt;

&lt;p&gt;They take full advantage of the expressive power of JavaScript's dynamic typing, no doubt about it.&lt;/p&gt;

&lt;p&gt;If we take into account the ability of the Static Type-System to capture as many potential problems as possible in Compile-Time, then redeveloping a Web services framework in TypeScript might be a worthwhile endeavor.&lt;/p&gt;

&lt;p&gt;Farrow is one of my outputs in this direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Middleware design from a TypeScript perspective
&lt;/h2&gt;

&lt;p&gt;Rich Harris, the author of Rollup and Svelte, recently shared his thoughts on &lt;a href="https://twitter.com/Rich_Harris/status/1304082928490733573"&gt;Next-gen Node HTTP APIs&lt;/a&gt;, and I was inspired.&lt;/p&gt;

&lt;p&gt;It started with a poll tweeted by Wes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0i_UiZxw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/592g6n0qcnilhfdpvxq8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0i_UiZxw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/592g6n0qcnilhfdpvxq8.png" alt="a poll tweeted by Wes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Close to 70% of developers, opted for expressjs style middleware function design. An overwhelming choice.&lt;/p&gt;

&lt;p&gt;Rich Harris' choice, with only 14.5% support.&lt;/p&gt;

&lt;p&gt;In that Gist, Rich Harris explains why he doesn't like the first option. Roughly, it goes as follows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always need to ugly pass &lt;code&gt;res&lt;/code&gt; parameters&lt;/li&gt;
&lt;li&gt;When combining middleware, you often have to do monkey-patching on &lt;code&gt;res&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;He gave what he felt was a better alternative design.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i1s-yV6B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cj4y2y9ixp5y4dgkx3wh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i1s-yV6B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cj4y2y9ixp5y4dgkx3wh.png" alt="a better alternative design"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply put, the &lt;code&gt;res&lt;/code&gt; parameter is eliminated, only the &lt;code&gt;req&lt;/code&gt; parameter is retained, the response result is expressed by return response, and the next middleware &lt;code&gt;next()&lt;/code&gt; is called by return void/undefined.&lt;/p&gt;

&lt;p&gt;Another developer, Oliver Ash, tweeted about one of the shortcomings of expressjs' middleware design - it does not take full advantage of Compile-Time's troubleshooting capabilities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VlNLdnoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tm3lytpc372m23x2theh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VlNLdnoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tm3lytpc372m23x2theh.png" alt="a tweet of Oliver Ash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In brief, when the response is the return value of middleware, TypeScript can type-check that each request must have a return value without fear of omission.&lt;/p&gt;

&lt;p&gt;Giulio Canti, the author of fp-ts, also has his own attempt - &lt;a href="https://github.com/gcanti/hyper-ts"&gt;hyper-ts&lt;/a&gt;. inspired by purescript's hyper project, hyper-ts uses TypeScript's Type- System to circumvent some common errors, such as: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PqvA0jhW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lhm2ez67q0i8aypfqyg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PqvA0jhW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lhm2ez67q0i8aypfqyg3.png" alt="some common errors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These clues all point to the conclusion that it may be possible to design the HTTP middleware API in a functional style (immutable way).&lt;/p&gt;

&lt;h2&gt;
  
  
  Farrow-Pipeline: Type-friendly middleware function design
&lt;/h2&gt;

&lt;p&gt;Farrow's middleware functions are inspired by Koa middleware, but are different.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eN-N-5ej--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z73ca7v3jlaos8ttvjad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eN-N-5ej--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/z73ca7v3jlaos8ttvjad.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above figure, we can learn the following information.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Response&lt;/code&gt; is not in the parameters of the middleware function, but from the plain function exported by farrow-http module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;response&lt;/code&gt; is the return value of the middleware function, which can be checked in Compile-Time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If there is no return value, it will look like the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SK9QvpUI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xxf4nt1zzlidnl38zh34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SK9QvpUI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xxf4nt1zzlidnl38zh34.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If an incorrect value is returned, it will look like the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rGcTfw1P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t0v42vy8nl32ukaryglq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rGcTfw1P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t0v42vy8nl32ukaryglq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The response to the client must be made by means of &lt;code&gt;Response.{method}()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KdbpXLLO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gni8qn1xxxi2vqs6bxkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KdbpXLLO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gni8qn1xxxi2vqs6bxkg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Response's API is designed to support Method Chaining, which can be called as follows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---AG9kFYe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nwyewwr9zjcy41elnf7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---AG9kFYe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nwyewwr9zjcy41elnf7v.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As above, setting response status, setting response headers, response cookies, and response content can all be written together elegantly.&lt;/p&gt;

&lt;p&gt;So, how does multiple middlewares collaborate with each other in Farrow?&lt;/p&gt;

&lt;p&gt;For example, in the upstream middleware, pass a new request to the downstream middleware, like the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wjx1h-Xk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3yhuyep14xjfblikh9g8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wjx1h-Xk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3yhuyep14xjfblikh9g8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second parameter of the Farrow middleware function is the &lt;code&gt;next&lt;/code&gt; function. Unlike expressjs/koajs middleware functions, the Farrow middleware function has both parameters and return values.&lt;/p&gt;

&lt;p&gt;Its parameter is the optional &lt;code&gt;request&lt;/code&gt; and its return value is &lt;code&gt;response&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When the &lt;code&gt;next()&lt;/code&gt; call is made without passing parameters, the downstream middleware gets the same &lt;code&gt;request&lt;/code&gt; as the upstream middleware.&lt;/p&gt;

&lt;p&gt;If a new &lt;code&gt;request&lt;/code&gt; is passed when &lt;code&gt;next&lt;/code&gt; is called, the downstream middleware will get the new &lt;code&gt;request&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;With this very natural parameter passing mechanism, we don't need to modify the current request. Even, Farrow sets the request type to read-only.&lt;/p&gt;

&lt;p&gt;Farrow encourages keeping the request/response immutable.&lt;/p&gt;

&lt;p&gt;Similarly, we can filter or manipulate the response returned by the downstream middleware in the upstream middleware, as follows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DbKxSFPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eopw3ynymipui7pdmky0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DbKxSFPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eopw3ynymipui7pdmky0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Response object provides a merge method to easily merge the status, headers, cookies, content, and other components of multiple responses.&lt;/p&gt;

&lt;p&gt;Farrow also provides a fractal-enabled Router design that helps us to fine-grained segment business logic into different modules and organically combines them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EUEjMzy1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iuzees3xuf37qdxrq80w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EUEjMzy1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iuzees3xuf37qdxrq80w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Farrow-Schema: Type-Safe Routing Design
&lt;/h2&gt;

&lt;p&gt;Farrow implements a powerful and flexible Schema-Based Validation that can match specific request objects in a type-safe manner.&lt;/p&gt;

&lt;p&gt;The basic usage is shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G3G6QZvJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7k3bvnfal8ey2klihuk8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G3G6QZvJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7k3bvnfal8ey2klihuk8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;http.match&lt;/code&gt; method accepts parameters as &lt;code&gt;{ pathname, method, query, params, headers, cookies }&lt;/code&gt; objects to form a &lt;code&gt;Request Schema&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;schema.pathname&lt;/code&gt; adopts expressjs-like style via &lt;code&gt;path-to-regexp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Farrow will extract the exact type of the matching request object through type infer according to the Request Schema, and validate it in the runtime to ensure the type safety of the request object.&lt;/p&gt;

&lt;p&gt;In addition, Farrow also implements type-safe route matching based on the Template Literal Types feature of TypeScript V4.1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YkiEtzfs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e302q8yh3lk610vtfeju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YkiEtzfs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e302q8yh3lk610vtfeju.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the  format in the path, we can combine { pathname, params, query }, write only one path, and extract the corresponding type from the path by type infer.&lt;/p&gt;

&lt;p&gt;A more complex case is shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RclhvNc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/icp0hadjywozhe9ztu0i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RclhvNc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/icp0hadjywozhe9ztu0i.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When &lt;code&gt;&amp;lt;key:type&amp;gt;&lt;/code&gt; appears before &lt;code&gt;?&lt;/code&gt; is treated as part of &lt;code&gt;params&lt;/code&gt;. The order is sensitive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When &lt;code&gt;&amp;lt;key:type&amp;gt;&lt;/code&gt; appears after &lt;code&gt;?&lt;/code&gt; appears after it, it is treated as part of the &lt;code&gt;query&lt;/code&gt;, where the order is not sensitive.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To learn more about Farrow's Router-Url-Schema, you can check out its &lt;a href="https://github.com/Lucifier129/farrow/blob/master/docs/http.md#router-url-schema"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Farrow-Hooks mechanism
&lt;/h2&gt;

&lt;p&gt;Another noteworthy feature in Farrow is that we take a cue from React-Hooks and provide a Farrow-Hooks mechanism to integrate with other parts of the server, such as logger, database-connection, etc.&lt;/p&gt;

&lt;p&gt;In contrast to koajs, which mounts extended methods with mutable &lt;code&gt;ctx&lt;/code&gt; arguments, in Farrow, the context is not an argument, but a Hooks.&lt;/p&gt;

&lt;p&gt;Like React-Hooks &lt;code&gt;useState&lt;/code&gt;, it can be seen as a fine-grained slicing of the &lt;code&gt;this.state&lt;/code&gt; shared in the class-component.&lt;/p&gt;

&lt;p&gt;Context.use in Farrow cuts the shared ctx in the same way. This is shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3u4mSn4W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m8mjh950pmh73jizx52r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3u4mSn4W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m8mjh950pmh73jizx52r.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We define a User type, create a Farrow Context in a similar way to React.createContext, and provide the default value (in this case, null).&lt;/p&gt;

&lt;p&gt;UserContext.use() is a built-in hook that provides access to the corresponding user context, and all Contexts are new and independent during each request -&amp;gt; response.&lt;/p&gt;

&lt;p&gt;Instead of having one big ctx, we have multiple small Context units.&lt;/p&gt;

&lt;p&gt;We can wrap custom hooks based on &lt;code&gt;Context.use()&lt;/code&gt;, such as &lt;code&gt;useUser&lt;/code&gt; in the above image.&lt;/p&gt;

&lt;p&gt;To dynamically update the value of a Context, do something like the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CXT608kR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i1fe7rmcxyjuh3bo4w1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CXT608kR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i1fe7rmcxyjuh3bo4w1k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Implement a Provider Middleware that dynamically and asynchronously updates the context value for consumption by the downstream middleware. The relationship is similar to that of Provider and Consumer in React Context. The upstream middleware is the Context Provider and the downstream middleware is the Context Consumer.&lt;/p&gt;

&lt;p&gt;With the Context Hooks mechanism, our middleware function type is always simple and stable, it only focuses on request -&amp;gt; response processing, other additional things can be provided through Hooks on demand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Farrow-React: A built-in component-based SSR
&lt;/h2&gt;

&lt;p&gt;Farrow provides an official SSR library, farrow-react, but you can also build your own SSR library based on methods like &lt;code&gt;Response.html&lt;/code&gt; or &lt;code&gt;Response.stream&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r9j-__rq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c86xtyhiq6msyq7w67b2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r9j-__rq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c86xtyhiq6msyq7w67b2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above, &lt;code&gt;farrow-react&lt;/code&gt; provides a Farrow-Hooks and through &lt;code&gt;useReactView&lt;/code&gt; we get a ReactView object that renders JSX into HTML and sends it to the browser through &lt;code&gt;farrow-http&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;farrow-react&lt;/code&gt; provides a &lt;code&gt;Link&lt;/code&gt; component to help us handle prefix-related auto-completion. To learn more, check out the official farrow &lt;a href="https://github.com/Lucifier129/farrow/blob/master/docs/react.md"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;At this point, we have broadly described a few of Farrow's core features.&lt;/p&gt;

&lt;p&gt;Farrow's goal doesn't stop there, we will build more farrow ecosystem in the future. For example.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;farrow-restapi&lt;/code&gt; and &lt;code&gt;farrow-restapi-client&lt;/code&gt; support reusing the schema/type of the server project in the client project to achieve type-safe functionality on the server/client side of the data transfer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;farrow-graphql&lt;/code&gt; and &lt;code&gt;farrow-graphql-client&lt;/code&gt;, similar to &lt;code&gt;farrow-restapi&lt;/code&gt; but with support for implementation via graphql.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;farrow-server-component&lt;/code&gt;, supports React Server Component.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is still a lot of work to be done, so if you are also interested, feel free to contribute to the &lt;a href="https://github.com/Lucifier129/farrow"&gt;Farrow&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>typescript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
