Friday, May 9, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

3 Ways to Simplify Frontends With Multiple Microservices

February 1, 2024
in Front-Tech
Reading Time: 3 mins read
0 0
A A
0
Share on FacebookShare on Twitter



Six months ago, one of our Angular Consulting clients reached out for assistance with their web app. They were facing difficulties testing the frontend code and were unsure how to resolve the issue. Bitovi provided three potential solutions to simplify the frontend code and make testing easier. In order to protect the client’s privacy, the code used in this article will be from a web app that was created to demonstrate the problem. The sample project includes different branches for each possible solution. Although the sample project is written in Angular, the problem it represents can occur in any frontend framework.

The Problem: Too Many Microservices

Imagine you are working on a web app that enables users to create, view, and edit invoices for their catering business. Your company already has existing microservices for various functionalities like customer data, addresses, and products, among others. Since other teams also rely on these microservices, it is not possible to make changes to them. When users want to create an invoice using your app, it utilizes the following component:

“`html
// create-invoice-page.component.ts
// https://github.com/kyle-n/catering-masters/blob/main/src/app/containers/create-invoice-page/create-invoice-page.component.ts

import { ChangeDetectionStrategy, Component } from ‘@angular/core’;
import { ActivatedRoute } from ‘@angular/router’;
import { Observable } from ‘rxjs’;
import { map, mergeMap } from ‘rxjs/operators’;
import { AddressService } from ‘src/app/services/address.service’;
import { CustomerService } from ‘src/app/services/customer.service’;
import { ProductService } from ‘src/app/services/product.service’;
import { Address } from ‘src/app/types/address’;
import { Customer } from ‘src/app/types/customer’;
import { LineItem } from ‘src/app/types/invoice’;
import { Product } from ‘src/app/types/product’;

@Component({
selector: ‘app-create-invoice-page’,
templateUrl: ‘./create-invoice-page.component.html’,
styleUrls: [‘./create-invoice-page.component.scss’],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CreateInvoicePageComponent {
protected customer$: Observable;
protected address$: Observable

;
protected products$: Observable;
protected lineItems$: Observable;
private customerId$: Observable;

constructor(
customerService: CustomerService,
addressService: AddressService,
productService: ProductService,
activatedRoute: ActivatedRoute
) {
this.customerId$ = activatedRoute.params.pipe(
map(params => Number(params[‘customerId’]))
);
this.customer$ = this.customerId$.pipe(
mergeMap(customerId => customerService.getCustomer(customerId))
);
this.address$ = this.customerId$.pipe(
mergeMap(customerId => addressService.getAddress(customerId))
);
this.products$ = this.address$.pipe(
mergeMap(address => productService.getProductsAvailableAtAddress(address.id))
);
this.lineItems$ = this.products$.pipe(
mergeMap(products => productService.getLineItemsForProducts(products))
);
}
}
“`

The constructor of this component is quite large. It performs the following tasks:

1. Retrieves the customer ID.
2. Uses the customer ID to load the customer data.
3. Uses the customer ID to load the customer’s address.
4. Uses the address ID to load the products available at that location.
5. Uses the products to load the line items for those products.

The constructor then loads this data into the template:

“`html

Create invoice

New Line Items


Potential Products



“`

The constructor relies on the customer$ and address$ observables to display the customer’s name and address in the header. Additionally, it needs the address$ observable to fetch the products$ observable, which is used to display a list of possible products. Finally, it needs the products$ observable to fetch the lineItems$ observable, which is used to display a table of line items. However, the constructor is difficult to modify and impossible to test.

Testing this constructor would require stubbing many functions, resulting in a test that does not accurately represent the real code. Breaking up the code is not a viable solution either since using private component methods to create the observables would only add unnecessary complexity. Moving this logic to a service is not possible either as the service would need to return an object containing four observables, making it less reusable and more challenging to locate.

This was the problem our client faced, albeit with more observables. I attempted three different solutions to address it.

Solution #1: Resolvers

The first approach I tried was using Angular Resolvers. Resolvers encapsulate the logic required to load specific data. For example:

“`typescript
// customer.resolver.ts



Source link

Tags: FrontendsMicroservicesMultipleSimplifyWays
Previous Post

Flipster Launches New Earn Pool Feature Allowing Users to Earn Up To 10K USDT Daily on Their Crypto – Blockchain News, Opinion, TV and Jobs

Next Post

Age-inclusive design for web interfaces

Related Posts

The essential principles of a good homepage
Front-Tech

The essential principles of a good homepage

June 7, 2024
How to measure and improve user retention
Front-Tech

How to measure and improve user retention

June 6, 2024
Push Animation on Grid Items
Front-Tech

Push Animation on Grid Items

June 5, 2024
How to build a Rails API with rate limiting
Front-Tech

How to build a Rails API with rate limiting

June 4, 2024
Introduction to the B.I.A.S. framework
Front-Tech

Introduction to the B.I.A.S. framework

June 3, 2024
Blue Ridge Ruby is exactly what we need
Front-Tech

Blue Ridge Ruby is exactly what we need

June 3, 2024
Next Post
Age-inclusive design for web interfaces

Age-inclusive design for web interfaces

Harmonizing AI-enhanced physical and cloud operations 

Harmonizing AI-enhanced physical and cloud operations 

Designing generative AI workloads for resilience

Designing generative AI workloads for resilience

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

May 19, 2024
A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

April 10, 2024
Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

November 20, 2023
Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

December 6, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In