Starts in:
0 DAY
22 HRS
24 MIN
59 SEC
Starts in:
0 D
22 H
24 M
59 S
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?


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',
        },
      },
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06