-
Notifications
You must be signed in to change notification settings - Fork 38
Simple HTTP requests library #1020
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
base: master
Are you sure you want to change the base?
Conversation
We could follow the other
(+ async-/streaming-related stuff of course) and then provide |
Apparently we could drop the node implementation and use fetch there, too; at least once we are sure all node versions we use are >=21: https://blog.logrocket.com/fetch-api-node-js/ |
For the dispatch, I'd wait for the resolution of #448. |
This comment was marked as resolved.
This comment was marked as resolved.
// Native Byte Buffers | ||
// ------------------- | ||
extern type NativeBytes | ||
// jsNode "Buffer" | ||
extern pure def length(n: NativeBytes): Int = | ||
js "${n}.length" | ||
extern pure def get(n: NativeBytes, x: Int): Byte = | ||
js "${n}[${x}]" | ||
def each(n: NativeBytes): Unit / emit[Byte] = { | ||
each(0, n.length){ i => | ||
do emit(n.get(i)) | ||
} | ||
} | ||
|
||
// Event emitters | ||
// -------------- | ||
extern type Undefined | ||
extern type EventEmitter | ||
record Event[T](name: String) | ||
namespace ev { | ||
def data(): Event[js::NativeBytes] = Event("data") | ||
def end(): Event[Undefined] = Event("end") | ||
} | ||
|
||
extern io def unsafeOn[T](em: EventEmitter, ev: String, handler: T => Unit at {io, async, global}): Unit = | ||
js "${em}.on(${ev}, (param) => $effekt.runToplevel((ks,k) => ${handler}(param, ks, k)))" | ||
def on[T](em: EventEmitter, ev: Event[T], handler: T => Unit at {io, async, global}): Unit = | ||
em.unsafeOn(ev.name, handler) | ||
extern async def unsafeWait[T](em: EventEmitter, ev: String): T = | ||
js "$effekt.capture(k => ${em}.on(${ev}, k))" | ||
def wait[T](em: EventEmitter, ev: Event[T]): T = | ||
em.unsafeWait(ev.name) |
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.
Those (and the async iterator stuff) might be independently useful for other Node APIs (namely child_process
) - do we have a convention where to put those kinds of "only for one backend, but used from common" things?
3a37619
to
406d068
Compare
CI fails due to #1075. |
92c1447
to
eb53d25
Compare
Co-authored-by: Jiří Beneš <[email protected]>
eb53d25
to
cf88469
Compare
This is a simple Proof-of-concept HTTP requests library in Effekt.
It forwards to the respective web/node APIs.
Additionally, it contains a (very much not production-ready) implementation of HTTP/1.1 in Effekt that reads/writes from/to Effekt streams (for integration with potential TCP bindings).