简体   繁体   中英

Best strategy for making API calls from stencil apps?

I am trying to use the npm init stencil in app mode. however, this creates a static app, without any api like configuration.....

should I rely on a global variable to configure the baseURL for api endpoints?

should I provide this value as a parameter on the app-root element?

what is the best strategy for this?

I ended up using the @stencil/redux package, and then created a apiClient object that I appended as a reducer....

this would allow me to write my redux actions like this:

export function myApiAction(param1, param2) {
  return  (dispatch, getStore) => {

    const client = getStore().apiClient;
    //dostuff here
    client.makeRequest().then( res => {
       dispatch({type: MY_API_RESULT, data:blah});
    });
  };
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM