RESTful HTTP client library with composable interceptor architecture for Node.js and browsers
76
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.
Install with Tessl CLI
npx tessl i tessl/npm-restevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10