GithubHelp home page GithubHelp logo

kitsonk / xhr Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 7.0 69 KB

An XMLHttpRequest polyfill for Deno CLI and Deploy ๐Ÿฆ•

License: MIT License

TypeScript 97.93% Dockerfile 2.07%

xhr's Introduction

xhr

xhr ci

A XMLHttpRequest polyfill for Deno CLI and Deno Deploy. The main intent is to make code written for a browser that uses XMLHttpRequest to fetch JSON, bytes, or text asynchronously work with Deno.

![WARNING] At this stage, this polyfill is very experimental and is not well tested. USE AT YOUR OWN RISK. Bug reports are welcome.

This polyfill has several known/intentional limitations from a browser standard XMLHttpRequest:

  • It does not handle XML, though the name implies it, nor does it handle HTML being treated as a response type "document". This uses the browser's built in parser to parse the XML and HTML into a DOM object.
  • Sync is not supported (passing false to the async argument). Most browsers have deprecated it in the main thread. Since this polyfill works by calling Deno's fetch() it is nearly impossible to generate a sync version, plus it is a really bad idea to block a thread while waiting for a server response. Don't do it, don't use software that requires it.

Usage

Import the module. The module will analyze the global scope, and if XMLHttpRequest and its associated APIs are not defined, it will add them:

import "jsr:/@kitsonk/xhr";

Now, XMLHttpRequest should be available in the global scope.

Types

The built in types for Deno do not include the XMLHttpRequest and associated types, so if you are type checking your code and get errors about them not being defined, there are a couple of solutions. If your code is generally written for the browser, you might want to consider Targeting Deno and the Browser section of the Deno Manual.

If all you want to do is "polyfill" the types, they are available here under ./globals.d.ts. You can either import them like:

import type {} from "jsr:/@kitsonk/xhr/globals";

Or using the triple slash reference like:

/// <reference types="jsr:/@kitsonk/xhr/globals" />

Copyright 2021-2024 Kitson P. Kelly. All rights reserved.

xhr's People

Contributors

kitsonk avatar lkwr avatar btoo avatar hirochachacha avatar wangbinyq avatar ibodev1 avatar

Stargazers

Tsiry Sandratraina avatar Asger Nielsen avatar Nicholas Berlette avatar Lewis Liu avatar Hyeseong Kim avatar cinchen avatar Umar Hansa avatar  avatar Dunkan avatar  avatar Jacob Hummer avatar Sung Jeon avatar Kenta Moriuchi avatar flow avatar spencer cap avatar Ray avatar michael spengler avatar  avatar Craig Morten avatar Yoshiya Hinosawa avatar Yuki Tanaka avatar Benjamin Fischer avatar Satya Rohith avatar

Watchers

James Cloos avatar  avatar  avatar

xhr's Issues

Custom method not allowed

I'm using the TSDAV package in Deno. https://tsdav.vercel.app/

I use it to interface with the CalDAV protocol.

CalDAV uses certain DAVMethods, in addition to traditional HTTPMethods:

type DAVMethods = 'COPY' | 'LOCK' | 'MKCOL' | 'MOVE' | 'PROPFIND' | 'PROPPATCH' | 'UNLOCK' | 'REPORT' | 'SEARCH' | 'MKCALENDAR';

The Deno port of cross-fetch, which this library depends on, uses your xhr library for the web requests. However, your library explicitly restricts non-standard HTTP methods:

Error: DOMException: The method "PROPFIND" is not allowed. at new DOMException (ext:deno_web/01_dom_exception.js:114:19) at XMLHttpRequest.open (https://deno.land/x/[email protected]/mod.ts:525:13)

Please remove this check, as it is preventing a legitimate use case of your library and is making the Deno environment more difficult for me to use.

Thank you very much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.