{"id":21031551,"url":"https://github.com/slaveofcode/grpc-restful-example","last_synced_at":"2025-12-26T20:37:03.195Z","repository":{"id":47948200,"uuid":"217006557","full_name":"slaveofcode/grpc-restful-example","owner":"slaveofcode","description":"Example implementation of Restful service with gRPC interaction between internal services (NodeJS)","archived":false,"fork":false,"pushed_at":"2021-08-11T14:54:22.000Z","size":115,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T15:25:53.402Z","etag":null,"topics":["grpc","grpc-client","grpc-node","grpc-server","restful-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slaveofcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-23T08:26:52.000Z","updated_at":"2021-01-22T12:55:32.000Z","dependencies_parsed_at":"2022-08-12T14:51:33.062Z","dependency_job_id":null,"html_url":"https://github.com/slaveofcode/grpc-restful-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fgrpc-restful-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fgrpc-restful-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fgrpc-restful-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fgrpc-restful-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slaveofcode","download_url":"https://codeload.github.com/slaveofcode/grpc-restful-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243472211,"owners_count":20296290,"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":["grpc","grpc-client","grpc-node","grpc-server","restful-api"],"created_at":"2024-11-19T12:29:13.587Z","updated_at":"2025-12-26T20:37:03.136Z","avatar_url":"https://github.com/slaveofcode.png","language":"JavaScript","readme":"# gRPC Client-Server Example with RESTful for the Front-end\n\nExample implementation of gRPC bwtween the internal microservices communications. The original request from the front-end is still using a Restful.\n\n**Note:**\n*This is just an example project, for those who wants to learn about gRPC on NodeJs.*\n\nThe illustration below is about how this project behave, so you may get the idea about how it's work under the hood.\n```\n\n                                               +----------------------+\n                                               |DB|                   |\n                         +                     +--+ +--------------+  +------+\n                         |                     |    |   Products   |  |      |\n                         |                     |    +--------------+  +\u003c---+ |\n                         |                     |                      |    | |\n                         |                     +----------------------+    | | Queries\n                         |                                                 | |\n                         |                                                 | |\n                    [Restful]                                              | |\n+-----------------+ HTTP Req    +----------------+ RPC Calls  +------------+-v+\n|                 +------+-----\u003e+                +------------\u003e               |\n| External Client |      |      | Client Service |            |   Server App  |\n|                 \u003c------+------+                \u003c------------+               |\n+-----------------+ HTTP Resp   +----------------+            +---------------+\n                         |\n                         |\n                         |\n                         |\n                         |\n                         +\n\n```\n\n## Data Flow\n\n1. HTTP Request coming from the front-end or client via **CURL** or another RESTful client (e.g. Insomnia, Postman, etc)\n\n2. **Client Service** requesting data through Rpc to the **Server App**\n\n3. **Server App** then doing a DB query and returning the result back\n\n4. **Client Service** got the result and return back to the original front-end or client.\n\n## Project Preparation\n\n1. Clone this project\n\n2. There are 3 subdirectories; `server` is a server of gRPC; `client` is a server of client which provide a restful service to the user, and `protos`  holds the `.proto` file for *product*.\n\n3. Go to `server` directory and install dependencies via \n\n```\n$ npm i\n```\n\n4. Do the same step on the `client` directory\n\n5. Create a new Postgres database called `grpc_products` (you may configure the username / password of the DB later on `server/knexfile.js`)\n\n6. Running the migration from the server directory\n```\n$ npm run migrate\n```\n\n7. Also the run the seeds \n\n```\n$ npm run seed\n```\n\n## Run the gRPC server\nGo to `server` directory and run `npm start`. If everything Ok you will see a message like\n```\n\u003e gRPC server running at http://127.0.0.1:1831\n\n```\n## Run the Restful server (Client of gRPC)\ngo to `client` directory and run `npm start`. You should see a message like this\n```\n\u003e Server run at 3000\n```\n\n## Testing RESTful request via CURL\n### List Products\n```\n$ curl http://127.0.0.1:3000/api/products \n\n{\n  \"products\": [\n    {\n      \"id\": 1,\n      \"name\": \"pencil\",\n      \"price\": \"1.99\"\n    },\n    {\n      \"id\": 2,\n      \"name\": \"pen\",\n      \"price\": \"2.99\"\n    }\n  ]\n}\n```\n\n### Read Product\n```\n$ curl http://127.0.0.1:3000/api/products/1\n\n{\n  \"id\": 1,\n  \"name\": \"pencil\",\n  \"price\": \"1.99\"\n}\n```\n\n### Create new Product\n\n```\n$  -X POST -d '{\"name\": \"lamp\", \"price\": \"18.8\"}' -H \"Content-Type: application/json\" http://127.0.0.1:3000/api/products\n\n{\"status\":\"Created\"}\n```\n\n### Update Product\n```\n$ curl -X PUT -d '{\"name\": \"Spoon\", \"price\": \"34.53\"}' \\\n-H 'Content-Type: application/json' http://127.0.0.1:3000/api/products/3\n\n{\"status\":\"Updated\"}\n```\n\n### Delete Product\n```\n$ curl -X DELETE http://127.0.0.1:3000/api/products/3\n\n{\"status\":\"Deleted\"}\n```\n\n## LICENSE \nMIT ([more](LICENSE))\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslaveofcode%2Fgrpc-restful-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslaveofcode%2Fgrpc-restful-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslaveofcode%2Fgrpc-restful-example/lists"}