Skip to content

Repository files navigation

request-utils

deno landGitHub release (latest by date)codecovGitHub

testNPM

Request utility collection.

equalsRequest

Check two Request fields equality.

import{equalsRequest}from"https://deno.land/x/request_utils@$VERSION/equal.ts";import{assert}from"https://deno.land/std/testing/asserts.ts";declareconsturl: URL;assert(equalsRequest(newRequest(url,{method: "HEAD"}),newRequest(url,{method: "HEAD"}),),);

If you also want to check the equivalence of the body, set the mode to strict.

import{equalsRequest}from"https://deno.land/x/request_utils@$VERSION/equal.ts";import{assert}from"https://deno.land/std/testing/asserts.ts";declareconsturl: URL;assert(awaitequalsRequest(newRequest(url,{body: "",method: "POST"}),newRequest(url,{body: "",method: "POST"}),true,),);

Throwing error

In strict mode, if request body has already been read.

import{equalsRequest}from"https://deno.land/x/request_utils@$VERSION/equal.ts";import{assert,assertThrows}from"https://deno.land/std/testing/asserts.ts";declareconsturl: URL;constrequest=newRequest(url,{body: ""});awaitrequest.text();assert(request.bodyUsed);assertThrows(()=>equalsRequest(request,request,true));

isRequest

Whether the input is Request or not.

import{isRequest}from"https://deno.land/x/request_utils@$VERSION/is.ts";import{assertEquals}from"https://deno.land/std/testing/asserts.ts";assertEquals(isRequest(newRequest("http://localhost")),true);assertEquals(isRequest({}),false);assertEquals(isRequest(null),false);

withHeader

Return an instance with the provided Request replacing the specified header.

There are no side effects on the original Request.

import{withHeader}from"https://deno.land/x/request_utils@$VERSION/with_header.ts";import{assert}from"https://deno.land/std/testing/asserts.ts";declareconstinit: Request;declareconstfieldName: string;declareconstfieldValue: string;constrequest=withHeader(init,fieldName,fieldValue);assert(request.headers.get(fieldName),fieldValue);assert(init!==request);

API

All APIs can be found in the deno doc.

License

Copyright © 2023-present httpland.

Released under the MIT license

Releases

Used by

Contributors

Languages