Live data from Hacker News

Cap'n Web: a new RPC system for browsers and web servers

blog.cloudflare.com

221–230 of 305 posts

Re: Cap'n Web: a new RPC system for browsers and web servers

#221

Earlier quoted context omitted.

The round trip happens when you `await` the result. You can tell that promise pipelining isn't adding any round trips because you set it all up in a series of statements without any `await`s. At the end you do one `await`. That's your round trip.

You say "round trip", but you mean "return trip", right? Because if I understand correctly, you don't queue the requests and then perform a single request/response cycle (a "round trip"), you send a bunch of requests as they happen with no response expected, then when an await happens, you send a message saying "okay, that's all, please send me the result" and get a response.

No, the requests are queued and sent as a batch.

Re: Cap'n Web: a new RPC system for browsers and web servers

#222

Earlier quoted context omitted.

You say "round trip", but you mean "return trip", right? Because if I understand correctly, you don't queue the requests and then perform a single request/response cycle (a "round trip"), you send a bunch of requests as they happen with no response expected, then when an await happens, you send a message saying "okay, that's all, please send me the result" and get a response.

No, the requests are queued and sent as a batch.

Ah, okay, that's much better then... In principle, that then allows the server to aggregate or optimise the operations rather than performing them as written. While that might not be relevant for version 1, it's useful to have for later.

Re: Cap'n Web: a new RPC system for browsers and web servers

#223

I was really excited when I saw the headline, but I was kind of disappointed to see it doesn't support schemas natively. I know you can specify them via zod, but I'm really not looking forward to any more untyped APIs, given that the lack of strict API typing has been by far the #1 reason for the bugs I've had to deal with in my career.

I really want to bake in some sort of support for generating type checks based on TypeScript types... so then your schemas are just TypeScript. Not sure why this doesn't seem to be a common practice TBH, might be missing something.

We built our own in-house RPC interface definition pipeline where the schemas are just typescript types, looking very similar to the example in your post

    interface MyService {
      method(): ReturnType;
    }
We parse the typescript to JSON Schema, then use that to generate runtime validation across both JS implementations and other languages.

Typescript is a really nice IDL. I didn't want to hitch our wagon to something else like typespec.io even if that would have given us more things out of the box.

Re: Cap'n Web: a new RPC system for browsers and web servers

#225
post #153
post #66

Earlier quoted context omitted.

The input to the map function (when it is called in "record" mode on the client) is an RpcPromise for the eventual value. That means you can't actually inspect the value, you can only queue pipelined calls on it. Since you can't inspect the value, you can't do any computation or branching on it. So any computation and branching you do perform must necessarily have the same result every time the function runs, and so…

> your function needs to have no side effects I'm trying to understand how well this no-side-effects footgun is defended against. https://github.com/cloudflare/capnweb/blob/main/src/map.ts#L... seems to indicate that if the special pre-results "record mode" call of the callback raises an error, the library silently bails out (but keeps anything already recorded, if this was a nested loop). That catches a huge number…

This ! Using the same name, i.e. `.map()` is a footgun, that devs would eventually fumble upon. `rpcMap()` sounds good. cc: @kentonv

Re: Cap'n Web: a new RPC system for browsers and web servers

#226
I am going to be that guy, the way REST is used in 99% of project deployments, it is yet another form of RPC, mostly JSON-RPC with a little help of HTTP verbs to save having yet another field for the actuall message purpose, all nicely wrapped in language specific SDKs, looking like method/function calls.

Re: Cap'n Web: a new RPC system for browsers and web servers

#227

I'm with WunderGraph, a vendor providing enterprise tooling for GraphQL. First, I absolutely love Capn Proto and the ideas of chaining calls on objects. It's amazing to see what's possible with CapNweb. However, one of the examples compares it to GraphQL, which I think falls a bit short of how enterprises use the Query language in real life. First, like others mentioned, you'll have N+1 problems for nested lists. Tha…

Side note, a lot of people these days build agents on top of APIs. GraphQL has selection sets, which allows you to select subsets of objects. This is quite handy when it comes to gents because of context window limitations.

Re: Cap'n Web: a new RPC system for browsers and web servers

#228
post #199
post #90

Earlier quoted context omitted.

In C#, there's expression trees which handle things like this and it's how Entity Framework is able to convert the lambdas it's given into SQL. This means that you can pass around code that can be inspected or transformed instead of being executed. Take this EntityFramework snippet: db.People.Where(p => p.Name == "Joe") `Where` takes an `Expression > predicate`. It isn't taking the `Func` itself, but an `Expression`…

C#, Swift, Dart, Rust... Python. Many languages take lambda/predicate/closure as filter/where. It generally unrolls as a `for loop` underneath, or in this case LINQ/SQL. C# was innovative for doing it first in the scope of SQL. I remember the arrival of LINQ... Good times.

How many of those languages can take an expression instead of a lambda?

Func is lambda that can only be invoked.

Expression> is an AST of a lambda that can be transformed by your code/library.

Re: Cap'n Web: a new RPC system for browsers and web servers

#229
post #90

Earlier quoted context omitted.

In C#, there's expression trees which handle things like this and it's how Entity Framework is able to convert the lambdas it's given into SQL. This means that you can pass around code that can be inspected or transformed instead of being executed. Take this EntityFramework snippet: db.People.Where(p => p.Name == "Joe") `Where` takes an `Expression > predicate`. It isn't taking the `Func` itself, but an `Expression`…

Is there anything C# _doesn’t_ have? :-) It feels like C# has an answer to every problem I’ve ever had with other languages - dynamic loading, ADTs with pattern matching, functional programming, whatever this expression tree is, reflection, etc etc. Yet somehow it’s still a niche language that isn't widely used (outside of particular ecosystems).

It's funny how C# started out as a Java clone and then added a ton of features while Java stayed very conservative with new language features. And both languages are fine.

Re: Cap'n Web: a new RPC system for browsers and web servers

#230

Earlier quoted context omitted.

There are inherent limitations with the "execute it once and see what happens" approach; namely that any conditional logic that might be in the mapping function is going to silently get ignored. For example, `db.people.map(p => p.IsPerson ? (p.FirstName + ' ' + p.LastName) : p.EntityName)` would either be seen as reading `(IsPerson, FirstName, LastName)` or `(p.IsPerson, p.EntityName)` depending on the specific behav…

> I wonder why they don't just do `.toString()` on the mapping function and then parse the resulting Javascript into an AST and figure out property accesses from that. That sounds incredibly complicated, and not something we could do in a <10kB library!

To the contrary, a simple expression language is one of those things that can easily be done in that size.
Post reply on HN