tessl install tessl/npm-rest@2.0.0RESTful HTTP client library with composable interceptor architecture for Node.js and browsers
Agent Success
Agent success rate when using this tile
76%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.29x
Baseline
Agent success rate without this tile
59%
Build a service that fetches data from a backend API and converts the response to different output formats. The service should leverage automatic content type handling for both request and response processing.
Create a function that:
Output Format Mappings:
'json' → application/json'form' → application/x-www-form-urlencoded'text' → text/plain@generates
/**
* Fetches a resource and formats it according to the specified output format.
*
* @param {string} resourceUrl - The URL of the resource to fetch
* @param {string} [outputFormat='json'] - The desired output format: 'json', 'form', or 'text'
* @returns {Promise<{data: string, contentType: string}>} The formatted response
*/
async function fetchAndFormat(resourceUrl, outputFormat = 'json') {
// IMPLEMENTATION HERE
}
module.exports = {
fetchAndFormat
};Provides HTTP client functionality with automatic content negotiation and MIME type handling.