<?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: Donald</title>
    <description>The latest articles on DEV Community by Donald (@donald).</description>
    <link>https://dev.to/donald</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%2F271727%2Ffa408a59-3675-4071-810c-00ce51b614d0.jpg</url>
      <title>DEV Community: Donald</title>
      <link>https://dev.to/donald</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/donald"/>
    <language>en</language>
    <item>
      <title>Formidablejs: The one person framework</title>
      <dc:creator>Donald</dc:creator>
      <pubDate>Sun, 30 Jan 2022 22:10:11 +0000</pubDate>
      <link>https://dev.to/donald/formidablejs-the-one-person-framework-mp9</link>
      <guid>https://dev.to/donald/formidablejs-the-one-person-framework-mp9</guid>
      <description>&lt;h2&gt;
  
  
  What is Formidable?
&lt;/h2&gt;

&lt;p&gt;Formidable (or formidablejs) is a Laravel inspired API framework for building backend applications. It uses &lt;a href="https://imba.io"&gt;Imba&lt;/a&gt; by default and has native support for JavaScript and TypeScript.&lt;/p&gt;

&lt;p&gt;While Formidable is meant to provide a smooth process for building API applications, you may also use it to build Fullstack applications thanks to &lt;a href="https://inertiajs.com/"&gt;Inertia&lt;/a&gt; and &lt;a href="https://laravel-mix.com/"&gt;Laravel Mix&lt;/a&gt; providing that "one person framework" feel.&lt;/p&gt;

&lt;p&gt;Formidable borrows a lot of its features from Laravel, and also uses &lt;a href="https://www.fastify.io/"&gt;Fastify&lt;/a&gt; under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  A few Formidable features
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Database
&lt;/h4&gt;

&lt;p&gt;Formidable has out of the box support for &lt;code&gt;SQL&lt;/code&gt; Queries and &lt;code&gt;Redis&lt;/code&gt;. The SQL data layer is powered by Knex.js, while the Redis data layer is powered by Node-Redis.&lt;/p&gt;

&lt;h4&gt;
  
  
  Migrations
&lt;/h4&gt;

&lt;p&gt;Out of the box, Formidable provides a simple database migration system that allows you to define and share your database schema definition. This is a great way to ensure that your database schema is always in sync with your application code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Auth
&lt;/h4&gt;

&lt;p&gt;Formidable provides a starter authentication system for both &lt;code&gt;session&lt;/code&gt; and &lt;code&gt;jwt&lt;/code&gt; based applications. By default, &lt;code&gt;session&lt;/code&gt; based authentication is enabled.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;session&lt;/code&gt; based authentication system enables the use of &lt;code&gt;cookies&lt;/code&gt;, and stores the session data in &lt;code&gt;memory&lt;/code&gt;, &lt;code&gt;file&lt;/code&gt; or &lt;code&gt;redis&lt;/code&gt;. While the &lt;code&gt;jwt&lt;/code&gt; based authentication system enables the use of JWT tokens, and stores authentication data in the database.&lt;/p&gt;

&lt;h4&gt;
  
  
  Routing
&lt;/h4&gt;

&lt;p&gt;Just like any other framework, routing has become a standard feature. Formidable provides a routing system similar to Laravel's router. You can easily group your routes, limit them to specific middleware's, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Error Handling
&lt;/h4&gt;

&lt;p&gt;Formidable has an Error Handler class which allows you to intercept any errors and return a different response. Formidable also provides Bugsnag out of the box.&lt;/p&gt;

&lt;h4&gt;
  
  
  CLI Tool
&lt;/h4&gt;

&lt;p&gt;Craftsman is the command line interface included with Formidable. Craftsman is installed as a global package and on every Formidable application. It provides a number of helpful commands that can assist you while you build your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project setup
&lt;/h2&gt;

&lt;p&gt;First thing you want to do, is install the CLI tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; @formidablejs/craftsman
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the CLI installation is done, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;craftsman new project-name &lt;span class="nt"&gt;--web&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;cd into the project folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;b&gt;Optional:&lt;/b&gt; should you want to install Vuejs or React, run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;craftsman inertia
&lt;span class="nv"&gt;$ &lt;/span&gt;npm run mix:dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When done with everything, serve your application using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;craftsman serve &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once Formidable is running, you can go to &lt;code&gt;http://localhost:3000&lt;/code&gt; in your browser to see if your application was successfully created.&lt;br&gt;
You should see the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wpmaRAzk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1m0ce84q3qb2jchp9hko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wpmaRAzk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1m0ce84q3qb2jchp9hko.png" alt="Formidable Welcome Screen" width="727" height="387"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Project structure
&lt;/h2&gt;

&lt;p&gt;Lets take a look at what our project looks like:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/app&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains the core code of your application.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/app/Http/Controllers&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains applicaiton controllers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/app/Http/Middleware&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains request middlewares.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/app/Http/Requests&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains form and API requests.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/app/Http/Models&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Houses &lt;code&gt;bookshelf&lt;/code&gt; models.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/app/Http/Resolvers&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains application service resolvers.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/bootstrap/cache&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains the cached config file and database settings file.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/config&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains application configuration files.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/database/migrations&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Houses your application migration files.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/public&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Houses your assets such as images, JavaScript, and CSS.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/resources/lang&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains language files.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/resources/views&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains Imba view class files.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/routes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains application routes.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/storage/framework&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains core application data.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/storage/session&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Contains application sessions.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: in some cases, you might see more folders; This is dependent on the type of project you created.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;
&lt;h4&gt;
  
  
  Creating your first Route
&lt;/h4&gt;

&lt;p&gt;To add a new route, open the &lt;code&gt;routes/web&lt;/code&gt; routes file and add the following lines at the bottom of the routes file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s"&gt;'/ping'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;do&lt;/span&gt; &lt;span class="s"&gt;'pong'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when visiting &lt;code&gt;http://localhost:3000/ping&lt;/code&gt;, you should see &lt;code&gt;pong&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating a Controller
&lt;/h4&gt;

&lt;p&gt;In the section above, I showed you how to create a route. Now, let's create a controller and map it to the route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;craftsman make controller HelloController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once created, you can open &lt;code&gt;app/Http/Controllers/HelloController&lt;/code&gt; and you should see the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;Controller&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s"&gt;'./Controller'&lt;/span&gt;

&lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;Controller&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create an action in the controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;Controller&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s"&gt;'./Controller'&lt;/span&gt;

&lt;span class="n"&gt;export&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;Controller&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
        &lt;span class="s"&gt;'Hello World'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding the &lt;code&gt;index&lt;/code&gt; action, you can go to your &lt;code&gt;routes/web&lt;/code&gt; file import your new controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;HelloController&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s"&gt;'../app/Http/Controllers/HelloController'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you've imported your controller, you can add a new route and map it to the action you created in the controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s"&gt;'hello'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;HelloController&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'store'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now see &lt;code&gt;Hello World&lt;/code&gt; when visiting &lt;code&gt;http://localhost:3000/hello&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For a fullstack demo application with crud operations see: &lt;a href="https://github.com/donaldp/pingcrm"&gt;https://github.com/donaldp/pingcrm&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kTv0_5dY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/donaldp/pingcrm/dev/screenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kTv0_5dY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/donaldp/pingcrm/dev/screenshot.png" alt="PingCRM Demo Application" width="880" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While Formidable provides a lot of useful features, it still has a long way to go before hitting a stable release. For now, just play around with it, report bugs and contribute if you can!&lt;/p&gt;

&lt;p&gt;Documentations: &lt;a href="https://formidablejs.org"&gt;https://formidablejs.org&lt;/a&gt;&lt;br&gt;
Github: &lt;a href="https://github.com/formidablejs"&gt;https://github.com/formidablejs&lt;/a&gt;&lt;br&gt;
PingCRM Demo: &lt;a href="https://github.com/donaldp/pingcrm"&gt;https://github.com/donaldp/pingcrm&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>node</category>
      <category>news</category>
      <category>mvc</category>
    </item>
  </channel>
</rss>
