if we had a model
User with the class method
create(name) then in JS we would just say
and that’d run this method on a server and return a result to JS сlient and it’d looked as if a function was defined in JS. Oh, I know you know that it’s called RPC and existed for a thosands of years, got wiped out by REST and generally considered
as bad practice. But why? Wouldn’t be more convinient than dealing with URLs and controllers? Web application is just
like any other distributed application consists of server and many clients that are talking to each other. Passing messages
and making remote procedure calls seems way more natural than hitting URL endpoints. URLs are understandable for people, but why make software talk this language?
To test this idea I made a simple lib https://github.com/yankov/nourl. You define a class on your backend side and it looks like this:
1 2 3 4 5 6 7 8 9
Then you run your server and in your JS it can be written like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
Especially taking in account that websockets probably are gonna be used more and more, I don’t see yet why this pattern wouldn’t work.
Some unnecessary text that tries to make post look cooler
A known fact: sometimes we keep doing things in an old way just because we get used to it even if it’s inconvinient. Handling this inconvinience quickly becomes a part of the standard routine which builds up our comfort zone. Usually it takes time to break the old layer of habbits and adapt to the new ideas. This is why people don’t care about craigslist’s UI although it doesn’t conform to any modern standards. Try to optimize it and people will rage (for a while).
So I was just trying to find things that we are doing in web-development that seem odd or obsolete, but to which we got used to and accepted as standards. One of such things is REST and using URLs for accessing APIs in general. Well, probably saying that REST is bad would be too arrogant, but there just could be other ways to go.
Remember, there was stuff like SOAP, RPC, Corba, RMI probably more familiar for people from the world of enterprise distributed software development. For a bunch of reasons it didn’t kick in web development: it was too cumbersome to deal with and not very natural for HTTP. But since we are moving on, web-applications more and more look like desktop application, websockets are gonna be widely spread out very soon, we probably have to find better ways to communicate clients with the servers rather than hitting URL endpoints.