{"id":18881129,"url":"https://github.com/intuition-dev/httprpc","last_synced_at":"2026-02-21T00:30:16.445Z","repository":{"id":36747561,"uuid":"224686035","full_name":"intuition-dev/httpRPC","owner":"intuition-dev","description":"httpRPC","archived":false,"fork":false,"pushed_at":"2022-12-22T15:08:58.000Z","size":63364,"stargazers_count":3,"open_issues_count":15,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T04:27:15.168Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/intuition-dev.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-28T15:51:57.000Z","updated_at":"2021-01-28T15:54:54.000Z","dependencies_parsed_at":"2023-01-17T04:30:21.430Z","dependency_job_id":null,"html_url":"https://github.com/intuition-dev/httpRPC","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intuition-dev%2FhttpRPC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intuition-dev%2FhttpRPC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intuition-dev%2FhttpRPC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intuition-dev%2FhttpRPC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/intuition-dev","download_url":"https://codeload.github.com/intuition-dev/httpRPC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239850449,"owners_count":19707348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T06:47:37.405Z","updated_at":"2026-02-21T00:30:16.382Z","avatar_url":"https://github.com/intuition-dev.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\n# HTTP-RPC\n\n#### Inspired by JSON-RPC and gRPC, but works over HTTP: specifically it works with a browser over http protocol.\n\n#### Marketing: Please star our main project here:\n- https://github.com/INTUITION-dev/INTU\n\n## HTTP-RPC\n\nInspired by JSON-RPC, but works over HTTP: specifically it works with a browser over http/s protocol. Google FireBase use gRPC, based on protocol buffers.  Other alternatives are REST and GraphQL.\nHTTP-RPC leverage browsers fetch() command. As a plus, it has built in edge cache: it can use both browser cache and CDN cache.\n\n\n## Features \n\n- Handles CORS and does so in a *single* trip - no pref light or double request\n- Built in error handling\n- Handles JWT token. Benefit is that it only checks the DB on login.\n- Has a field for the calling entity (or page or screen), so you know what screen/page called the RPC. \n- Can use regular headers for caching at at edge w/ CDN or at the browser.\n- Timeout, configurable\n- Browser side AND server side calls/invokes.\n- Idempotent capability, configurable\n- Early TLS handshake via CDN edge\n- Can track VM (ViewModel) registry\n\n### Notes\n- The https should be provided by the CDN/Edge. It makes for a faster https handshake. Also, some CDN offer QUIC (http v3) protocol.\n- Recommended practice is that if you have 2 screens calling same RPC: have 2 distinct RPC handlers back-end, that can later call the\nsame business logic.\n- Likely you'd use JWT w/ IAM  (eg. AWS Cognito or Backendless )\n\n## Questions?\n- Open a ticket\n\n# How to use:\n\n### Part I: Server side\n\nSteps:\n\n1. Write a server side method that you want to use. Often these are DB CRUD methods, but here is a multiply example, this is the method we will call from the browser:\n\n   ```\n   function doMultiply(a,b) {\n      return a*b\n   }\n   ```\n\n2. Write a handler that calls above method. First you'll need to add the package and import :\n\n   ```\n   npm i http-rpc\n   \n   import { BaseRPCMethodHandler, Serv } from 'http-rpc/node-srv/lib/Serv'\n   ```\n\nAnd an example handler:\n\n   ```\n   class Handler1 extends BaseRPCMethodHandler {\n      constructor() {\n         super(2,1) \n      }\n\n      multiply(params) {\n         let a = params.a\n         let b = params.b\n         return [TOKEN, doMultiply(a,b)]  // note that data is array[1]\n      }//()\n   }\n   ```\n\nHere the doMultiply() calls the method in step 1.\nAlso our constructor sets the cache to 2,1: the browser will cache for 2 seconds and CDN for 1. You can set this to 0,0.\n\n3. Now we need the http server that will route to the handler(s).\n\nOur service takes an array of approved CORS domains, eg:\n\n   ```\n   const service = new Serv(['*'])\n   const h1 = new Handler1()\n   service.routeRPC('api', h1 ) // route to handler\n   service.listen(8888)\n   ```\n\nA route /api will be handled by Handler1!\nWe now have a running service with one handler and that handler has one method 'multiply' (that is then passed on to the business layer).\n\n\n### Part II: Client side\n\n Now call your remote method:\n\n   ```\n   import { HttpRPC } from 'https://cdn.jsdelivr.net/npm/http-rpc@2.5.0/webApp/httpRPC.min.js'\n\n   const rpc = new HttpRPC('http', 'localhost', 8888)\n   let params = {a:5,  b:2, token:TOKEN}\n   let ans:any = await rpc.invoke('api', 'multiply',  params  )\n   // console.log(ans[0])//token\n   console.log(ans[1])\n\n   ```\n##### Note: You can get a token from jwtUtil in lib folder.\n\nConstructor is self explanatory. \nThe invoke() method takes the route ('api') and a method in the handler to call ('multiply'), plus the arguments( 5 and 2).\nIt returns a promise with a result.\n\nOther: of course you'd likely have more than one handler, and each handler would handle more than one method.\n\nSo that is how to use http-rpc in 5 steps.\n\n\n### Demo\n\n[\u003cimg src=\"http://img.youtube.com/vi/FYZqz-AvwRo/0.jpg\" width=\"400\"/\u003e](http://www.youtube.com/watch?v=FYZqz-AvwRo)\n\n\n\n### Aside: Why \n\nFor me, RPC solves an organizational issue like so: I manage a back-end team, and a front-end team.\nThe back-end seemed to be hands-of with any issues related to front-end calling remote services.\n\nSo in order to get the back-end team engaged, I made the back-end team responsible for the client side service|api calls to the backend.\nBack-end team is responsible for documenting client side API calls, testing, fail-over, handling-time outs, encoding protocol(eg: JSON | MsgPack), versioning, \ncapacity planing, performance, etc. If we use Swift, Kotlin, .js on front-end; the back-end team has to write an API in that language. \u003c/br\u003e\nThe front-end developers have a tough job w/ the front-end, among other thing due to a large number of libraries.  So the back-end team helps by writing the API calls\nfor each and every screen | page.\nAnd the back-end team even help support the ViewModel, reducing any impedance that maybe related to back-end entity mapping. In general if the API call is slow or any issue,\nthen it is the back-end team's problem. \n\nSo the logical next step for the back-end team: start writing helper classes to call the remote service, hence HTTP-RPC+ was born, as a result of back-end \nteam being responsible for the Client side calls.\n\nWe did try JSON-RPC, but that had issues over HTTP and world wide web. So we mimicked that and built HTTP-RPC+. There is a node.js reference implementation, and also a Java port.\n\n#### Other RPC links:\n- https://thomashunter.name/posts/2017-09-27-is-it-time-to-replace-rest-with-rpc\n- https://dzone.com/articles/a-quick-introduction-to-http-rpc\n\n\n#### More\n\nThis repo houses other backend/full stack code and examples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintuition-dev%2Fhttprpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintuition-dev%2Fhttprpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintuition-dev%2Fhttprpc/lists"}