-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Http request with BodyInit #267
Http request with BodyInit #267
Conversation
Hi @a-khakimov - sorry for the slow reply. I've been stuck on a long piece of work in another repo. Will check it out as soon as I get back to Tyrian. 👍 |
Hi @davesmith00000! Just wanted to check in regarding PR and see if you’ve had a chance to take a look. Thanks, and appreciate your time! |
Good morning @a-khakimov, |
@@ -41,6 +43,7 @@ enum Body derives CanEqual: | |||
* the content of the body | |||
*/ | |||
case PlainText(contentType: String, body: String) extends Body | |||
case File(contentType: String, body: BodyInit) extends Body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be ok, but I'm a bit worried about using BodyInit as a catch-all type. I am entirely open to counter arguments. 🙂
I haven't tried this so this is speculation, but from reading around I think we need something like this (though this seems cumbersome):
enum Body derives CanEqual:
case Empty
case PlainText(contentType: String, body: String)
case File(contentType: String, body: org.scalajs.dom.File)
case Blob(contentType: String, body: org.scalajs.dom.Blob)
case FormData(contentType: String, body: org.scalajs.dom.FormData)
case ArrayBuffer(contentType: String, body: org.scalajs.dom.ArrayBuffer)
case TypedArray(contentType: String, body: org.scalajs.dom.TypedArray)
case URLSearchParams(contentType: String, body: org.scalajs.dom.URLSearchParams)
case ReadableStream(contentType: String, body: org.scalajs.dom.ReadableStream)
It also feels like we could do with an enum of content types, and then we could provide helper methods so that you could do things like:
def bodyImagePng(data: Blob): Body =
Body.Blob(ContentType.imagePng, data)
Or something. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A list of content types is a big 'ol list - maybe just types we support? I suspect for now you probably just want PlainText
, File
, and Blob
to start.. dealing with application/json
and application/xml
are problems all on their own for another time 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly crossed wires (or I'm just wrong, wouldn't be the first time 😁 ), we're not talking mime-types, we're talking bodyinit types - I think that's the whole list ☝️.
References:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#parameters
https://fetch.spec.whatwg.org/#bodyinit-unions
An XMLHttpRequestBodyInit, which per the Fetch spec can be a Blob, an ArrayBuffer, a TypedArray, a DataView, a FormData, a URLSearchParams, or a string.
Not...sure...where I got ReadableStream
from... 🤔
Does that change anything for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this because I've been unintentionally sitting on it. It is an improvement that solves a problem, thank you for the work and I'm very sorry it's taken such a long time to approve.
I still think there's more to do here, but I've left a placeholder issue that points back to here for some future person to look at:
#290
I need to figure out how to rerun this build to make sure it's passing before I merge.
Thanks again!
Update: Can't figure out how to re-run it but I've run it locally and it seems ok.
I made a small draft that solves my problem #266. I suggest making such a change to support http requests with a body for other types, not only text.