type Method = 'get' | 'post' | 'put' | 'delete' ; export function parseEndpoint ( endpoint , pathParams = { } ) { const [ method , rawPathname ] = endpoint . split ( ' ' ) ; const pathname = Object . keys ( pathParams ) . reduce ( ( acc , paramName ) => { return acc . replace ( `{${ paramName }}` , pathParams [ paramName ] ) ; } , rawPathname ) ; return { method : parseMethod ( method ) , pathname } ; } export function parseMethod ( method ) { const res = method . trim ( ) . toLowerCase ( ) as Method ; if ( ! [ 'get' , 'post' , 'put' , 'delete' ] . includes ( res ) ) { throw new Error ( 'Endpoint was not prefixed with a valid HTTP method' ) ; } return res ; }