Takes a Resource object and returns its path as a string, with any path parameters replaced with their corresponding values. Optionally, it can ensure that the returned URL has a trailing slash.

const resource = {
path: 'users/{id}/messages',
params: { id: 1 },
};

getUrlFromResource(resource, false); // 'users/1/messages'
getUrlFromResource(resource, true); // 'users/1/messages/'
  • Type Parameters

    • TPath extends string

      A string literal representing the path template with placeholders.

    Parameters

    • resource: Resource<TPath>

      The Resource object containing the path and parameters.

    • OptionalensureTrailingSlash: boolean

      If true, the returned URL will have a trailing slash.

    Returns string

    The URL with all placeholders replaced by the corresponding values from params.