about 3 years ago Syntax Podcast
RPC in JavaScript!
- 00:35 Wes introduces RPC
- 01:56 Wes defines RPC
- 02:41 Wes explains client-server RPC
- 03:12 Scott clarifies RPC is a concept, not a spec
- 03:57 Wes says there are RPC standards/specs
- 04:59 Scott says RPC is gaining popularity due to React server components
- 06:00 Wes says React doesn't have RPC yet but it's being discussed
- 06:27 Wes explains calling server functions from client with RPC
- 07:00 Scott says Meteor used RPC
- 08:45 Wes explains directly calling server functions from client
- 10:04 Wes mentions Solid JS server functions for RPC
- 11:13 Wes compares RPC to REST
- 12:26 Wes gives drone control example
- 13:27 Scott asks about multiple clients with RPC
- 14:48 Wes explains multiple connections like websockets
- 15:06 Scott asks about third party API access
- 15:57 Wes talks about authentication options
- 16:16 Scott explains trpc blurs RPC/REST
- 17:23 Scott mentions great trpc episode
- 17:46 Wes talks security considerations
- 18:24 Scott says he likes RPC developer experience
Scott explains trpc blurs RPC/REST
Wes Bos
I did listen to it, but it should have, Yes.
Wes Bos
what tRPC is sending Other things, security, on a let's use client server as an example. RPC can obviously be used
Scott Tolinski
It just feels like our PC, right, where,
Scott Tolinski
wish I would have been on that that call. Yeah, that that episode was great because I had a lot of
Scott Tolinski
I believe it's it's just over rest APIs. It's just this layer that that sits in between your API that Makes that connection feel like it's tightly coupled, even though it is just a layer in front of it. Yeah, and
Wes Bos
the function as well as any arguments. That's how most of these t r p c's I'm just looking at I should
Scott Tolinski
for more information. But t r PC
Scott Tolinski
our PC where Essentially, it feels like you're just calling methods and doing our PC, but it isn't traditional our PC.
Wes Bos
of
Wes explains directly calling server functions from client
Scott Tolinski
But you you get some of the same concepts of being able to access server side functionality
Scott Tolinski
directly within whatever is your UI code. But now we're going to do it in a slash client and server basis,
Scott Tolinski
if And don't forget to subscribe in your podcast player because
Scott Tolinski
don't matter as much as I have an interface, and I would like this interface to manipulate some data on the back end. And that's That's typically the reason why I tend to like our PC myself. Exactly. Solid JS. We had Ryan on the podcast Monday. They are introducing It it was DDP. It was similar concept, though. So for me, this concept has always felt very fine, like, to to do these types of things. Right? It it all just feels very normal to me. But, again, like I said, with the pendulum coming back around, it's like, that is available to you that goes directly along with the fact that it is just like a concept, right? It's not the implementation
Scott Tolinski
call some sort of a function. You're just trying to manipulate some data somewhere, the database, whatever. And you're not necessarily thinking, oh, I have a client that needs to send a message to the like, Those are the details that honestly
Scott Tolinski
how I think about the way my application works. Because at the end of the day, you're just trying to
Wes Bos
a server function, which is basically you just our kids get them quite a bit. So I'm wondering if if they're gonna go down the same route. But, yeah, they just like little plastic tubes in your ears and they help I don't think any of the authentication stuff Will change, especially because
Scott Tolinski
Me, personally, I I don't necessarily see that blending of client and server as being too much of an issue conceptually, But Yeah. And it does, again, bring us back 2 almost PHP style things where you're not even though we weren't working on the client, then you're just working on the server. So it's not the same.
Scott Tolinski
which honestly, experience of using RPC style clients, RPC clients in general. But, again, or even just a REST API,
Wes gives drone control example
Wes Bos
the command right up front. And then I think there's like a space or an equal sign. And then any arguments that you want to come along run this function and pass it another function, and then it will fetch
Scott Tolinski
I have not dove into any of that world, so it's it's so fascinating for me to hear any of that.
Wes Bos
And There's no there's no URL to ping on the drone, right? There is
Wes Bos
It will send back to you as a response from that. It will send back to you the actual data. So you could say like battery
Wes Bos
are sent over that. And then a function or you're running some code
Wes Bos
through that you can just send, because you're like, I can call all these like restricted like, better ease of use code gen. Yeah. It feels like TypeScript would be easier that way. Yeah. Like like, t r p c is an example. Right? You wanna talk about that? React and Siblings, I could just call directly the functions that I've written on my server from the client.
Scott Tolinski
Yeah. That's interesting.
Wes Bos
And signals to the drone.
Scott Tolinski
Yeah.
Wes Bos
a socket connection. I think it's a socket connection.
Wes Bos
would. But in my case, it was being sent over a socket,
Transcript
Announcer
Open wide dev fans, get ready to stuff your face with JavaScript, CSS, node modules, barbecue tips, get workflows, breakdancing,
Wes Bos
What does that mean? The word that has a RPC. I didn't even know that. Interesting. Yeah, it's XML based RPC.
Announcer
Monday. Monday. Monday.
Announcer
Boss, and Scott
Announcer
soft skill, web development, the hastiest, the craziest, the tastiest TS Webb development treats coming in hot. Here is Wes, Barracuda,
Wes compares RPC to REST
Wes Bos
Electron sends it over some, Soap was bring your data where you send a request. It's generally over HTTP or it's always over HAB because REST is a URL endpoint.
Scott Tolinski
of the thing. Right?
Wes Bos
And it's generally based on your HTTP get, put, delete methods.
Wes Bos
via any protocol and any method
Wes Bos
most of the functionality does overlap with REST. REST is more in electron call that function on the server and then and you pass it a function. You pass it all your local arguments and that will all get sent to the server.
Wes says React doesn't have RPC yet but it's being discussed
Wes Bos
as you write these server components,
Wes Bos
Generally, the idea is that
Wes Bos
sometimes you might not even need Radio waves. If you're thinking about controlling a drone, right?
Wes Bos
inside of your components. However you like, you can write SQL query right inside of your server component.
Wes Bos
The idea is that you could just pull data controller to a drone. It can be done from
Wes Bos
an API. You might
Scott mentions great trpc episode
Scott Tolinski
assumptions in my brain about what t r p c was. And it was so good to get that pulled out, say, no. It's more of this and it's more of this. And these are the oh, like, it did. It simultaneously did more things
Scott Tolinski
and more and less things than I thought at the same time. Oh, yeah.
Wes talks security considerations
Wes Bos
it can be a little bit of a blur because you are calling it from the client. You might think, like,
Wes Bos
because you are calling it from the client However, there's talk of it. There's people building stuff on top of server components for it.
Wes Bos
the security as well as it would be. So definitely and have it run on the server.
Wes Bos
I think that That's what we got there. I'm very curious to see if this type of thing will sort of take off. I guess we'll keep all eyes on We had the folks from Quik on as well. Quik City has a router loader, which is kind of similar to the thing we're talking about with React, where you can I used to get them all the time as a kid, and I had tubes put in my ears.
Wes Bos
You sort of have to make sure that your security is buttoned down, there's JSON RPC, of something for like stateful documents as many people that were connected to the Wi Fi network of that drone could send and receive
Scott says Meteor used RPC
Wes Bos
what's the one that we talked about that's like a Electron killer built in Rust? There's gRPC, I forgot what it's called, some sort of bus.
Wes Bos
and you can send stuff across
Wes Bos
API methods from the client call server dollar I listen to it that I'm kind of bummed that that's the only syntax I've ever missed.
Wes Bos
where
Wes Bos
electron works is that you have your your application, right? And then you have your your your like node process that was running Awesome. Alright. Thanks, everybody, for tuning in. We'll catch you later. Peace.
Wes Bos
Save just I'm assuming it's a like a JSON string
Scott Tolinski
Tory.
Scott Tolinski
Okay.
Wes Bos
Meteor allowed you just to straightaway call like database queries from the client, which is wild. But is
Wes Bos
Hey, don't have to like send a request to the server and then the server has to accept that request and then translate it to whatever I want. I can literally just call like I know, items and that would
Wes Bos
Tori has an even better implementation of that where you can just surface your functions to the client and it works really, really well in that you just You just call them. You can call file.
Scott Tolinski
Now other people are starting to feel the vibe for why these things actually might feel good sometimes to use. Yeah. Another popular one is
Wes defines RPC
Wes Bos
call.
Wes Bos
like the browser, It can be done from your phone to a robot.
Wes Bos
with anything.
Wes Bos
Essentially what it is, Go back to my YouTube. I have a video on controlling a drone with JavaScript.
Wes Bos
It can be done from a which was wireless. Right? Mhmm.
Wes Bos
like, literally one thing to another. And generally, Yeah. That's awesome.
Wes Bos
means remote procedural go, there are several standards out there.
Wes Bos
from the client
Wes Bos
your logic, like the server,
Wes Bos
is when you are
Wes talks about authentication options
Scott Tolinski
Yeah. Yeah. T r p c is well, t r p c is interesting because go back and listen to the the whole show we did on on t r PC itself, really kind of blurs that line between Here's how this thing works.
Scott Tolinski
You can get access to,
Scott Tolinski
Okay. Well,
Scott asks about third party API access
Wes Bos
RPC is not just HTTP, right? Like it could be a header if you are doing it over HTTP, but it could also
Wes Bos
on level
Wes Bos
it. You just have to
Wes Bos
a Oh, no, no. With the drone one, I had to connect to the Wi Fi network. So that was the security level at that point, right? So a handful of soap APIs in my day,
Wes Bos
where you need to do like a handshake and get a token first before you send it along. I'm pretty sure with the drone one, I had to send along And it would just say display RPC commands and it's the format is a little bit funky. It like requires you to put and something that is more powerful or something that is actually running, key. Welcome to Syntax, the podcast with the tastiest web development treats out there. Today, we've got a show for you on RPC. PC.
Scott clarifies RPC is a concept, not a spec
Scott Tolinski
Not a specific technology itself. It's not RPC.
Scott Tolinski
all RPC or anything like that. It is not a specific technology, not a spec, just a concept, right? the tight coupling could be seen as a pro in the considerations
Scott Tolinski
And so Unlike GraphQL,
Scott Tolinski
GraphQL is a spec. GraphQL is here's how to do it, and then people implement that spec in whatever library. But RPC is more just like, here's a general concept.
Scott Tolinski
Js that is your server and your client. Right? Because if you if your server is that tightly integrated with your client,
Scott Tolinski
for our PC, but our PC itself is not a spec. It's a concept.
Wes says there are RPC standards/specs
Wes Bos
used And then RPC the the result of that, just like any normal function
Wes Bos
there's an XML based one out there. Soap? need a REST API or GraphQL API or something like that.
Wes Bos
which is never fun actually use it returns are several, as specifications and then any percentages that you want, and then it will return to you It's funny because you wrote it's not a spec, and then I wrote it is a spec. And we're both right here. And Scott said it is that
Wes Bos
XML to you, which is brutal to work with. But yeah, there's lots of different standards out there. And generally, when you're working with an API, they'll say, alright, this is a gRPC API or this is a JSON RPC API. So a you have a point here. It's just why are we talking about our PC? Like, why now? to see if this type of thing becomes more popular in building APIs.
Wes Bos
Oh, man. I had unfortunately and you might not think about And then if you wanted, you can expose things like refresh, refresh, mutations, all of that kind of thing, and you could expose those
Wes explains calling server functions from client with RPC
Scott Tolinski
back to you. Yeah. Which is funny for me coming from a meteor background.
Wes Bos
procedurally Like it's a little like a sort of a step lower in that the RPC can be sent figure out how is the authentication being sent over right? Is it is it is it username password? Is it a token based? for RPC just yet.
Wes Bos
remotely You might be sending RPC calls over.
Scott Tolinski
You know,
Scott Tolinski
meteor was an RPC.
Wes Bos
directly to the client. So you could have a button that says on click
Wes explains client-server RPC
Scott Tolinski
a lot of technologies to talk from client server. Right? Our PC is a concept has been around for a long time. And just like the pendulum of a lot of things that come back around,
Scott Tolinski
conceptually.
Wes Bos
actually is, is you are calling can be sent over any protocol. So there are packages out there for working with RPC in WebSockets.
Wes Bos
and then as if it were being done on
Wes Bos
And that's what an RPC
Scott Tolinski
I think will confuse some people considering we have
Wes Bos
Remotely,
Wes explains multiple connections like websockets
Wes Bos
to your server
Scott Tolinski
third party access to your API, like, opening up your server to interrupt from other people. There's always like an authentication
Wes Bos
and the server can Respond accordingly to each of those. I don't think that's an issue because, like, what about, like,
Scott asks about multiple clients with RPC
Scott Tolinski
What about considerations here? And, I think one consideration, some things that might freak some people out would be the tight coupling between And, they they all kind of get mushed together in a way this,
Scott Tolinski
a I don't I don't even know. Like, what is the what is the way of doing our PC with multiple different front end. I don't even know. What do you mean multiple front? Like, if you had a client with if you had a mobile app and a web app and you had a,
Wes Bos
from different clients out there? Like if you it's like it's like a WebSocket. If you had a, Let's say you're sending the RPC calls over a WebSocket.
Scott Tolinski
of the 2 of those so tightly could make that a our PC as a concept is something that people are now for a full archive of all of our shows.
Scott Tolinski
And because of that, the the coupling There are different specs,
Scott Tolinski
all these different new eyes and all these different clients interfacing with the server.
Scott Tolinski
via that API and handle those accordingly, which is largely why things like GraphQL
Scott Tolinski
you might be wondering, like, well, how do I have multiple And to to be clear here because this is something that
Scott Tolinski
Yeah, third party third party access to your API. There's there's really not a lot of solutions there. No, I would just like Can't a server accept multiple connections
Scott Tolinski
you have your server, and that server Can accept incoming messages,
Scott Tolinski
then. With something like GraphQL So I I think yeah. And and rest is is like you mentioned, it is closely connected to those HTTP methods where our PC is more or less not connected at all directly to those as a concept. Yeah. Like, I exist. Right? So that you could have yeah, I I'm like we You said I'm mostly here to just consume the consume the things that are are given to us, and I'll just say, okay. Sure. Okay. I'll take it.
Scott Tolinski
clients
Scott says he likes RPC developer experience
Scott Tolinski
Yeah. Yeah. Totally. And, again, I I personally don't the big thing about our PC is that it's a concept or design pattern. It's not a spec specifically.
Scott Tolinski
feel that strongly either way about it. I I I don't mind a lot of the things that people are upset about when they think about our PC.
Scott Tolinski
Or drop a review if you like this show.
Wes Bos
Peace.
Wes Bos
Head on over to syntax.fm from the client to the server via RPC. And then even,
Scott Tolinski
Mhmm. You know, they're you'll find people argue anything on on Twitter. But me personally, I do like, the developer
Wes mentions Solid JS server functions for RPC
Wes Bos
So there's a lot of talk about it recently, and I don't know if it's necessarily just like hype, which is it's kind of funny because like, again, this stuff has been around for 20, 30 years, everything runs on the server by default or any of the APIs that you are thinking of from the client, which at first feels a little bit weird once you sort of understand it. Oh, this is actually kind of nice. I don't have to hopscotch my way from the client to the server and then translate that every single time I want.
Wes Bos
Right? Yeah, but there seems to be a lot of My name is Wes Bos. With me as always is mister Talinsky. How are you doing today, Scott? Oh, hey. Hey. Hey. I'm doing okay.
Wes Bos
And yes,
Wes Bos
hype around it because of this new So other questions. Isn't this just rest? Like, What you're describing is just a REST endpoint.
Scott Tolinski
in JavaScript. And I'll tell you why. There's hype around it. There's hype around it because anytime introducing some of these concepts to people that they might not have come across before. You know, a lot of developers picked up React is their 1st
Scott Tolinski
React does anything, even things that have existed for a long time, people act like it's a a big deal. Yeah. Yeah. Well, every act invented this thing or yeah. Who knows? rest and, we'll talk a little bit about some of these considerations here in just a minute, but, like, I there's many times when I really like that approach.
Wes Bos
you're looking for on the server.
Wes Bos
all the data that you're Can't you can make multiple WebSocket connections
Scott says RPC is gaining popularity due to React server components
Scott Tolinski
or coming, whatever, you know, the idea of our PC,
Scott Tolinski
essentially between your clients and server as it is, Is becoming a little bit more in vogue or in the the the mind's eye of the entire development community now. Exactly. And it's worth saying that there is nothing in React in addition though, the
Scott Tolinski
connection I, I I'm on antibiotics again for, like, the Oh, wow. Which,
Scott Tolinski
talking a lot more about now that we have,
Scott Tolinski
So now that server components are here,
Scott Tolinski
introduction to, you know, web programming in general.
Wes introduces RPC
Wes Bos
drain all the disgusting stuff out.
Scott Tolinski
All of a sudden to be like, oh, you have an ear infection. I was like, what? What's going on? Yeah. So, that that's the status of my life right now. But, Hey, other than that, doing good. Awesome. Well, let's get on into it. RPC
Wes Bos
Oh, man.
Wes Bos
Let's try to explain it, for you from the context of a JavaScript developer.
Scott Tolinski
2nd time this suit in the last 30 days. I I I just, like, cannot get healthy. I I have no idea what's going on with me right now. So,
Scott Tolinski
I got an ear infection. When was the last time you got an ear infection?
Wes Bos
forever in computing, but it seems to have gained quite a bit of popularity in the JavaScript world, especially as we're starting to get more into
Wes Bos
been around for probably the actual client. Yeah.
Scott Tolinski
Yeah. I know. I like I never had our kids don't get them. I never really had one. So I don't even know when the last time I had one was. So, like,
Wes Bos
server side rendering our JavaScript app. So we thought, there is something that is less powerful, have to step in and make sure all of that stuff is buttoned down.