Open Closed

How to change RestService http client options for gnerated service proxy #2053


User avatar
0
moustafa created

If you're creating a bug/problem report, please include followings:

  • ABP Framework version: 4.4.3
  • UI type: Angular
  • DB provider: EF Core

Hi

i'm using abp-generate-proxies

so i have service like that

@Injectable({ providedIn: 'root', }) export class MessagingService { apiName = 'Default';

sendCodeByMobile = (mobile: string) => this.restService.request<any, MyResponse<boolean>>({ method: 'POST', url: '/api/app/messaging/sendCode', params: { mobile } }, { apiName: this.apiName });

verifyCodeByCode = (code: string) => this.restService.request<any, MyResponse<boolean>>({ method: 'POST', url: '/api/app/messaging/verifyCode', params: { code } }, { apiName: this.apiName });

constructor(private restService: RestService) { } }

i need to add option withCredentials: true because im using asp/net core sessions

for now i can edit the servive manually to add withCredentials option so the service would become like that

@Injectable({ providedIn: 'root', }) export class MessagingService { apiName = 'Default';

sendCodeByMobile = (mobile: string) => this.restService.request<any, MyResponse<boolean>>({ method: 'POST', url: '/api/app/messaging/sendCode', params: { mobile }, withCredentials: true }, { apiName: this.apiName });

verifyCodeByCode = (code: string) => this.restService.request<any, MyResponse<boolean>>({ method: 'POST', url: '/api/app/messaging/verifyCode', params: { code }, withCredentials: true }, { apiName: this.apiName });

constructor(private restService: RestService) { } }

but if i run using abp-generate-proxies again my changes will be lost

How can i achieve that ?

hope the question is clear


3 Answer(s)
  • User Avatar
    0
    Mehmet created

    Hi @moustafa,

    See the proxy generation README.md content:

    # Proxy Generation Output
    
    This directory includes the output of the latest proxy generation.
    The files and folders in it will be overwritten when proxy generation is run again.
    Therefore, please do not place your own content in this folder.
    
    In addition, `generate-proxy.json` works like a lock file.
    It includes information used by the proxy generator, so please do not delete or modify it.
    
    Finally, the name of the files and folders should not be changed for two reasons:
    - Proxy generator will keep creating them at those paths and you will have multiple copies of the same content.
    - ABP Suite generates files which include imports from this folder.
    
    > **Important Notice:** If you are building a module and are planning to publish to npm,
    > some of the generated proxies are likely to be exported from public-api.ts file. In such a case,
    > please make sure you export files directly and not from barrel exports. In other words,
    > do not include index.ts exports in your public-api.ts exports.
    

    If you change any generated code via ABP CLI's generate-proxy command, you need to move that out of the proxy folder.

  • User Avatar
    0
    moustafa created

    Hi Mehmet Thank for your reply but but actually you didn't answer my question

    Is there any way to control http client options without editing the generated service. same as can I edit api name

  • User Avatar
    0
    Mehmet created

    Unfortunately, there is no way to control HTTP client options. What I suggest is when you create a proxy, move the generated files to another folder and modify them.

    As for api name, you can pass --api-name option to generate-proxy command. Please see the document below for more information: https://docs.abp.io/en/abp/latest/CLI#generate-proxy

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11