Open Closed

How to generate and use a proxy for a none-default api #3856


User avatar
0
trevor.wilson created

I have added a second API to my environment

apis: {
    default: {
      url: 'https://localhost:44360',
      rootNamespace: 'default.namespace',
    },
    myapi: {
      url: 'http://myapi:1234',
      rootNamespace: 'MyProj.myapi',
    },
  },

I would like to generate a proxy the API named myapi. I tried to generate the proxy using the following command:

abp generate-proxy -m myapi -t ng --api-name myapi

The abp cli successfully generated the proxy using this command. I then import the proxy service in my component:

import { MyService } from '@proxy/myproj/root/myservice.service';

but when I make calls to MyService the request has the default base URL. For example, calling myService.getList results in a request that looks like this:

https://localhost:44360/api/myapi/myservice

Why is the base url not being taken from myapi? What am I doing wrong?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    muhammedaltug created

    Hello,

    What is the apiName of generated MyService class? It should be equal to the key in the environment.ts

    Example

    import { Injectable } from '@angular/core';
    @Injectable({
      providedIn: 'root',
    })
    export class MyService {
      apiName = 'MyApi';
    }
    
    apis: {
        default: {
          url: 'https://localhost:44360',
          rootNamespace: 'default.namespace',
        },
        MyApi: {
          url: 'http://myapi:1234',
          rootNamespace: 'MyProj.myapi',
        },
      },
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.