Fork me on GitHub
#clojure
<
2023-06-18
>
hifumi12306:06:08

I want to create a simple HTTP API whose implementation is "async all the way down." How does pedestal compare with async http-kit? Ideally, I'd like to use core.async with my implementation, but I just want something that will allow be to implement as many things async as possible. (For this reason, I am looking for Ring alternatives. Middleware are inherently synchronous.)

p-himik06:06:25

Ring 2 has async middleware.

p-himik06:06:43

Can't answer about the comparison, but Aleph might be a thing to look at.

igrishaev06:06:45

Perhaps you'd better to stick with Aleph + manofold. Aleph provides an async HTTP server

igrishaev06:06:18

plus async HTTP client for interaction with 3rd party resources, websockets, etc

hifumi12306:06:39

Hmm... I thought Manifold was an alternative to Aleph after the author of Aleph learned some things while maintaining Aleph.

Ben Sless06:06:54

Manifold and Aleph go together

Ben Sless06:06:10

Ring has async arity for middlewares

hifumi12306:06:05

I'll look into both again, thanks! @U2FRKM4TW Regarding Ring 2, I havent looked to deep into it yet, but for now I want to stick with "stable" solutions. @UK0810AQ2 Yeah, I'm aware of the 3-arity pattern specified in Ring 1.5(?), but middleware still need to call a function to retrieve response maps IIRC, whereas interceptors allow some form of queuing of things to change and dont depend on the return results of a function.

Ben Sless06:06:30

Interceptors don't perform as well

Ben Sless06:06:44

So yes, you need to explicitly pass the request and response, it's a hassle

Ben Sless06:06:01

I wrote a small helper library to help me with the common cases

didibus06:06:02

Is ring 2 out yet?

pesterhazy09:06:51

Is async still desirable now that we have loom?

2
hifumi12309:06:06

I don't use non-LTS releases of Java and Clojure doesn't officially support them either AFAIK

Ben Sless10:06:39

@U06F82LES For now I'd say yes, the ecosystem isn't fully prepared for it yet, not to mention Clojure itself isn't ready wrt thread pinning, so I'd wait for a bit

👍 2
didibus11:06:06

What's the difference between ring 1.6 async handlers and 2.0 ?

phill16:06:29

Pedestal lets your async request handler return a core.async channel. While core.async does not have exceptions and is therefore not easy to use in an airtight way, Pedestal provides non-happy-path async features in its interceptor model. With Pedestal you organize interceptors as a list (and they can modify the list) instead of coding handlers calling handlers calling handlers. Aleph is a (Netty-based) webserver built on Manifold, which implements an async model that includes exceptions - very pleasant and capable and well-suited to general-purpose web-serving. Manifold is a work of art! But Aleph's innovation is all in Manifold, without the async-native higher-level interceptor stuff that's in Pedestal. Last I was aware, Aleph did not have any provision for serving HTTP/1.0 responses (minimum 1.1). Netty is both a server and a client, so Aleph is super excellent for writing webservers that are also clients of other HTTP services, because you can program them both in the same async framework: seamless and elegant.

didibus19:06:23

Wasn't sure which channel to ask this. I've got a Clojure script (can also run in Babashka) I need it to execute once a week, it scrapes some websites and calls some APIs and renders some HTML. Then I want it to update the HTML in some static server. And then I want a way to serve that static HTML. What cloud/hosting setup would be cheapest or even free for this? (and maybe easy and quick to setup)

borkdude20:06:08

I think you can do this all via github actions (cron jobs + pages)

phronmophobic20:06:54

I've been using github's hosting for some small projects and have been happy with that. I have a paid account which is pretty cheap, but I think you get some amount of hours for free for open source projects. A generic setup can be similar to: • create an action that runs on a https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule • inside the action, create a static build • use the pages action to deploy

👍 2
borkdude20:06:52

I've also got one in https://github.com/borkdude/cljs-showcase I think it uses the similar github action

phronmophobic20:06:35

I've also used s3 for static hosting which can be cheap and effective.

didibus20:06:18

Cool, I wondered if GitHub actions could somehow be used. I'll check that out, seems simpler and cheaper than going with say Lambda + EventBridge + S3

vemv20:06:43

I use GCP's S3 thingy for (a handful of static assets) and pay 0.02/mo, has been the case for some 5 years? For building yeah, CI is a natural fit for CD

Patrick01:06:31

If you have a VPS you could point nginx at the directory you want to serve and then just set up a cron job