import url from "url" ; param { import ( "axios" ) . AxiosRequestConfig } config returns { import ( "axios" ) . AxiosRequestConfig } export const urlParamsMiddleware = ( config ) => { let { query , pathname , ... rest } = url . parse ( config . url , true ) ; config . urlParams = config . urlParams || { } ; for ( const param in config . urlParams ) { if ( pathname ?. includes ( `:${ param }` ) ) { pathname = pathname . replace ( `:${ param }` , config . urlParams [ param ] ) ; } else { query [ param ] = config . urlParams [ param ] ; } } config . urlParams . baseUrl = config . baseURL ; return { ... config , originalUrl : config . url , url : url . format ( { ... rest , pathname , query } ) } ; } ;