XMLHttpRequest for Node.js that emulates the browser XMLHttpRequest object
Overall
score
75%
Build a small client module that performs asynchronous HTTP requests for common CRUD-style actions against a JSON resource endpoint and exposes parsed responses.
/items/42 resolves asynchronously using the configured base URL and returns the parsed JSON body with status 200. @test/items/42 completes without a body, sends caller-provided headers, and returns the response headers. @test/items sends the provided JSON payload and resolves with the created representation and status 201. @test/items/42 sends the provided JSON payload and returns the updated representation and status 200. @test/items/42 completes asynchronously with status 204 and an empty body. @test@generates
export type HttpHeaders = Record<string, string>;
export type HttpResult = {
status: number;
body?: any;
headers: HttpHeaders;
};
export interface ResourceClient {
get(path: string, headers?: HttpHeaders): Promise<HttpResult>;
post(path: string, data: any, headers?: HttpHeaders): Promise<HttpResult>;
put(path: string, data: any, headers?: HttpHeaders): Promise<HttpResult>;
remove(path: string, headers?: HttpHeaders): Promise<HttpResult>;
head(path: string, headers?: HttpHeaders): Promise<HttpResult>;
}
export function createResourceClient(baseUrl: string, defaultHeaders?: HttpHeaders): ResourceClient;Provides a browser-style HTTP request interface for Node.js.
Install with Tessl CLI
npx tessl i tessl/npm-xmlhttprequestdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10