question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for custom request-function

See original GitHub issue

Describe the solution you’d like In our last project, we have used a custom axios setup to access the backend. One thing that would not have been possible with “openapi-typescript-codegen” is the axios-interceptor that retrieves the the current language settings from “i18next” and adds a query parameter to the outgoing request. It was very convenient to do it this way, because from that point on, we didn’t have to worry about transmitting the correct language anymore.

I would like to see a mechanism that uses a custom request-function. That way, everybody can write an adapter if needed.

The following changes

// OpenAPI.ts
export type RequestFunction = (options: ApiRequestOptions) => Promise<ApiResult>;

interface Config {
    BASE: string;
    VERSION: string;
    WITH_CREDENTIALS: boolean;
    TOKEN: string | (() => Promise<string>);
    requestFunction?: RequestFunction;  // added
}

// request.ts
export async function request(options: ApiRequestOptions): Promise<ApiResult> {
     if (OpenAPI.requestfunction != null) {
         return OpenAPI.requestFunction(options);
     }
     ...
}

would allow a configuration similar to the bearer-token:


OpenAPI.requestFunction = async (options) => {
    ...
    return {
        ...
    }
}

I briefly thought about using your library in our project, but it was too late by then. In the next project, maybe. It could be a huge time-saver.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yondhcommented, Feb 16, 2022

@ferdikoomen Do you have an example of registering an interceptor on axios client?

1reaction
nils4coseecommented, Nov 2, 2020

I have had a look at the swagger-spec of our API again. The query-param is currently not part of all endpoints. This is mainly, because we auto-generate the spec from the Spring-Boot endpoints and the query-parameter is processed in a Filter before the Controller classes are invoked. Since the parameter is universal, I would like to treat it in a universal fashion in the frontend as well. And I really don’t want to pull any Java-dependencies into the frontend project…

The change could also be done by adding a new request-type (“customRequest” instead of “node”, “xhr” or “fetch”) which creates a function that delegates to OpenAPI.requestFunction. I think the result could still be called “lightweight”. It would not add any dependencies. It would be the responsibility of user to provide the request function, including any dependencies.

I can create a small PR to illustrate what I mean.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Request Function - vue-tables-2
Custom Request Function. by default the library supports `JQuery`, `vue-resource` and `axios` as ajax libraries. If you wish to use a different library, ......
Read more >
Custom request function for missing translations #65 - GitHub
This may help. btw: the passed in custom request function is also called for missing requests, you may just check if it is...
Read more >
How to add additive Authorization parameter in vue-tables-2 ...
I managed to run request as: requestFunction(data) { let credentialsConfig= JSON.parse(JSON.stringify(settingCredentialsConfig)) ...
Read more >
Request Custom Functions - SDP help desk guide
Custom functions are built on Deluge, Zoho's propriety scripting language. Custom actions can be used in Business Rule, Custom Trigger, and Request Life...
Read more >
ACE Support | U.S. Customs and Border Protection
Remember: CBP does not provide support for 3rd party software. ... Receiving access to Export Reports (new data request function); Running Export Reports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found