Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose Request, Response globally #2108

Closed
JamesKyburz opened this issue Apr 13, 2019 · 16 comments
Closed

expose Request, Response globally #2108

JamesKyburz opened this issue Apr 13, 2019 · 16 comments
Milestone

Comments

@JamesKyburz
Copy link

If fetch is available as a global should we not also expose Request, Response and friends like the browser environment does?

@kitsonk
Copy link
Contributor

kitsonk commented Apr 13, 2019

Request and Response are there, just not exposed globally.

Is there a use case for exposing them globally?

@JamesKyburz
Copy link
Author

Request can be used by fetch instead of string and options.

However both Request and Response are global the browser environment.

Response would be nice to be able to mimic a Cloudflare worker locally (which has already been done in node)

@ry
Copy link
Member

ry commented Apr 13, 2019

True, it is global in the browser. We ought to make it global in deno too.

@hayd
Copy link
Contributor

hayd commented Apr 14, 2019

Is there a way to generate a list of globals in chrome/Firefox/deno? That way could enumerate what is intentionally omitted vs what is awaiting implementation.

This would also be nice as documentation...

@kitsonk
Copy link
Contributor

kitsonk commented Apr 14, 2019

That would be a long long list. I think use case driven is still the best way. We are not going to implement name for example. 😄

@benjamingr
Copy link
Contributor

I think there is merit in collaborating with the JS standard library spec proposal to see if Deno can have a say on what's exposed.

There are things the browser exposes it makes no sense for Deno to expose and vice versa.

@ry
Copy link
Member

ry commented Apr 14, 2019

I didn't mean to suggest that Deno should have feature parity with browsers - that would be very difficult and beyond the scope of Deno. But where we provide a certain API (in this case fetch() and its associated Request) I think we shouldn't change how it's presented (in this case by having Request not be a global)

@benjamingr
Copy link
Contributor

benjamingr commented Apr 14, 2019

@ry true, though that might be confusing since the type Request will also be exported globally (right?) which might be confusing since request can be:

  • An HTTP Request I'm making through fetch.
  • An http request I received on the server.

The two are not necessarily a different type. (This was intentional in the design of fetch and service workers).

If projects like deno_std/http used Request (rather than ServerRequest) that would be cool since it'd align them with service workers and fetch.

@hayd
Copy link
Contributor

hayd commented Apr 14, 2019

It would be a long list but I imagine the vast majority will be labelled "intentionally omitted"!

@JamesKyburz
Copy link
Author

Looking at the code it looks like ReadableStream could also be exposed?

@akircher
Copy link

akircher commented Apr 14, 2019

I don't think ReadableStream is WhatWg compatible so think making it global right now might be more confusing than helpful. I haven't seen a reason why Deno doesn't use a WhatWg compatible API. If the Deno implementation doesn't plan on browser compatability here, I think it would be good to rename the Deno implementation or namespace it, so we don't paint ourselves in a corner and are unable to offer a spec based implementation in the future.

UPDATE: Not sure if am correct with this assessment. My opinion was based on an old thread.

@benjamingr
Copy link
Contributor

@akircher see old discussion in #387

@rsp
Copy link
Contributor

rsp commented Apr 16, 2019

For a list of JS global objects (i.e. those from the language spec, not the DOM) see:

(but some of them are not exposed as real globals - see my unexposed module on npm for more info)

The host objects available in browser contexts are available on MDN here:

(not everything on one place but a good start)

It makes sense to make everything global that is global in browsers, and nothing else (to avoid conflicts in the future)

@ry ry changed the title expose more globals expose Request, Response globally Apr 23, 2019
@ry ry added this to the v0.4 milestone Apr 23, 2019
This was referenced Apr 26, 2019
@ry
Copy link
Member

ry commented Jun 10, 2019

Fixed in #2253

@ry ry closed this as completed Jun 10, 2019
@bartlomieju
Copy link
Member

Looks like Response is implemented in //js/fetch.ts but it is still not exposed globally - see commented out code in globals.ts

CC @ry @kitsonk

@kitsonk
Copy link
Contributor

kitsonk commented Jun 13, 2019

My advice, don't comment it out. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants