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 utility that inspects HTTP API responses and extracts specific information. The utility should provide convenience methods to examine different aspects of API responses without requiring users to handle complete response objects.
@generates
Implement the following functions:
getResponseBody(url) - Makes a request to the given URL and returns a promise that resolves to only the response bodygetStatusCode(url) - Makes a request to the given URL and returns a promise that resolves to only the status codegetAllHeaders(url) - Makes a request to the given URL and returns a promise that resolves to all response headersgetHeader(url, headerName) - Makes a request to the given URL and returns a promise that resolves to the value of the specified headercheckContentType(url) - Makes a request to the given URL and returns a promise that resolves to the Content-Type header valueAll functions should handle both successful and error responses appropriately.
/**
* Get only the response body from an HTTP request
* @param {string} url - The URL to request
* @returns {Promise<any>} Promise resolving to response body
*/
function getResponseBody(url) {
// IMPLEMENTATION HERE
}
/**
* Get only the status code from an HTTP request
* @param {string} url - The URL to request
* @returns {Promise<number>} Promise resolving to status code
*/
function getStatusCode(url) {
// IMPLEMENTATION HERE
}
/**
* Get all response headers from an HTTP request
* @param {string} url - The URL to request
* @returns {Promise<object>} Promise resolving to headers object
*/
function getAllHeaders(url) {
// IMPLEMENTATION HERE
}
/**
* Get a specific response header from an HTTP request
* @param {string} url - The URL to request
* @param {string} headerName - The name of the header to retrieve
* @returns {Promise<string>} Promise resolving to header value
*/
function getHeader(url, headerName) {
// IMPLEMENTATION HERE
}
/**
* Get the Content-Type header from an HTTP request
* @param {string} url - The URL to request
* @returns {Promise<string>} Promise resolving to Content-Type value
*/
function checkContentType(url) {
// IMPLEMENTATION HERE
}
module.exports = {
getResponseBody,
getStatusCode,
getAllHeaders,
getHeader,
checkContentType
};Provides HTTP client capabilities for making requests.