PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] How to manage axios in monorepo

 October 13, 2022     axios, monorepo, typescript, vuejs3     No comments   

Issue

I have monorepo with multiple clients and I try figure out how to manage axios in this project.

Assumptions:

  1. Multiple clients may or may not have the same interceptors,
  2. clients have shared API endpoints (shared composables i.e. user.composable -> getUser(): IUser), but also have own ( user.composable -> getClientXData(): unknown) which cannot be compiled and visible at others builds.
monorepo/
├─ apps/
│  ├─ client1/
│  │  ├─ composables/
│  │  │  ├─ user.composable.ts
│  ├─ client2/
│  │  ├─ composables/
│  │  │  ├─ user.composable.ts
│  ├─ client3/
│  │  ├─ composables/
│  │  │  ├─ user.composable.ts
├─ packages/
│  ├─ composables/
│  │  ├─ user.composable.ts
│  ├─ models/
│  │  ├─ IUser.ts

Do you have any ideas how to manage this?


Solution

I would have create an axios service package which any app can consume, but not exactly as it sounds.

First, avoid adding interceptors on the default axios instance. Instead, create new instances which any app will consume by it own needs. (you can also defined shared interceptors for them on the default axios instance)

In addition, I might follow OOP principals with Factory Design Pattern. I would have create a class with all shared API endpoints, and some other classes for each app or behavior which extends the base class with it own API endpoints. now any app can consume the axios-service and get it relevant endpoints the property it pass to the factory.



Answered By - Yarin Barnes
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing