Skip to content
Muhammad Firdaus Sati edited this page Feb 4, 2024 · 1 revision

🔥 Blaze

An event driven framework for 🔥 Hono.js

Table of Contents

What Is Blaze?

In a large-scale application where there's a lot of dependencies between each service, there is chances that we need to re-use some of the code from different services. The easiest way to solve these issues is just copy and paste the code that we need from the other services. Unfortunately, this way of doing will result to a non-reuseable code which can lead to a code bases that hard to maintain.

To solve these issues, Blaze offers you to have a way to communicate between services internally using our BlazeContext API. Therefore, the needs to use the same code can be done by just doing a function call from other services. By using our BlazeContext API in case an error occurred you can easily identify the problem is it in the service that you are working on or in the service that your service are depends on.  

What Is Blaze For?

Blaze is designed to do the following:

  • Communication between service internally by just a function call.
  • Automatically send a REST API response in case of an Error occurred.
  • Trigger a certain service action after a service action completed.

What Does Problem Blaze Solve?

In a large-scale application where you have a lot of dependencies between services, there is a chance's that you will need a certain function from Service A to be able to use it in Service B. Instead of copy and pasting the code that you need or importing the function from Service A to Service B, you just call that function directly from Service B and just focus on the Service B that you developed.

For example, if someone registering to your website and after the registration completed, you need to send an email to your user to inform them that their registration is successful. For this scenario, you can just call the function that handle all the emailing in your backend, but you need to remember that the emailing function need to be added after the registration process are completed. In case you forgot to do so, that means the user will not receive the email and you doesn't meet the completion criteria for those functions. By using Blaze you can trigger a certain function/action after that function/action are completed using our service/action hooks API.

// register.user.ts

rest: 'POST /register',
hooks: {
  async after(ctx, res) {
     // handle the emailing here
     // or call the email service from here
     ctx.emit('email.registered', res)
   }
}

What Design Principles Underlie Blaze?

Blaze works by:

  • Event Driven pattern.
  • Automatically send an error message on REST API error.
  • Single code responsibility (actions/hooks).

How Does Blaze Accomplish Its Goal?

Blaze does this by:

  • Wrap all the action/hooks promises and check does an error occurred or not.
  • Expose BlazeContext API on every actions/hooks so it can communicate between services.