{"id":16234159,"url":"https://github.com/zackify/swift-web-grpc-example","last_synced_at":"2026-01-16T00:56:43.264Z","repository":{"id":39203360,"uuid":"245512741","full_name":"zackify/swift-web-grpc-example","owner":"zackify","description":"Example Swift GRPC Server and web client","archived":false,"fork":false,"pushed_at":"2023-01-05T09:17:28.000Z","size":4206,"stargazers_count":0,"open_issues_count":21,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T03:47:24.475Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/zackify.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-03-06T20:42:18.000Z","updated_at":"2020-03-06T20:47:57.000Z","dependencies_parsed_at":"2023-02-03T22:31:57.511Z","dependency_job_id":null,"html_url":"https://github.com/zackify/swift-web-grpc-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/zackify%2Fswift-web-grpc-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fswift-web-grpc-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fswift-web-grpc-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackify%2Fswift-web-grpc-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackify","download_url":"https://codeload.github.com/zackify/swift-web-grpc-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819751,"owners_count":20839094,"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-10-10T13:15:10.760Z","updated_at":"2026-01-16T00:56:43.235Z","avatar_url":"https://github.com/zackify.png","language":"Swift","readme":"## GRPC Example\n\nThis is a little grpc example using a swift grpc server, and a basic js web client.\n\nRunning the code is the easy part, inside the swift folder, `swift run Server`.\n\nInside web, `yarn` `yarn start`\n\n## Gotchas\n\nAlong the way I learned that generating code from protobufs is a bit finicky in swift and JS. Most of my issues were inside swift though, because the grpc-swift package is currently undergoing a rewrite, you have to pull down the beta branch, manually build the swift protobuf and grpc binaries. THEN you can correctly generate swift code from a protobuf.\n\nOn the JS side, it was easier, download their listed binary, and run the command. But I find the process a bit annoying. Having to manually download a binary when theres an update needs to be automated on our machines... bazel? ;)\n\n## Swift\n\nOn the swift side, I mostly copied the example code, but learned a lot by manually generating the code and reading through it thoroughly. I find the swift code less verbose than JS, but could still be a little shorter. Here's an example request:\n\n```swift\nclass GreeterProvider: Helloworld_GreeterProvider {\n  func sayHello(\n    request: Helloworld_HelloRequest,\n    context: StatusOnlyCallContext\n  ) -\u003e EventLoopFuture\u003cHelloworld_HelloReply\u003e {\n    let recipient = request.name.isEmpty ? \"stranger\" : request.name\n    let response = Helloworld_HelloReply.with {\n      $0.message = \"Hello \\(recipient)!\"\n    }\n    return context.eventLoop.makeSucceededFuture(response)\n  }\n}\n```\n\nFor the most part it's \"just a function\" with the request data passed in. These types are all generated for you from the protobuf generator for swift.\n\n## JS\n\nAlso, the commands are really crazy looking. Here's how i generated the required JS code for a basic protobuf:\n\n```\nprotoc -I=. helloworld.proto \\\n--js_out=import_style=commonjs:. \\\n--grpc-web_out=import_style=typescript,mode=grpcwebtext:.\n```\n\nLastly, I find the JS synax to be very verbose, and it also doesnt support async/await currently:\n\n```js\nlet client = new GreeterClient('http://localhost:51318');\n\nlet request = new HelloRequest();\nrequest.setName('Test name');\n\nclient.sayHello(request, null, (err, res) =\u003e {\n  if (err) return console.log(err);\n\n  console.log('got stuff from grpc', res.getMessage());\n});\n```\n\nI would have expected something much cleaner, like:\n\n```js\nlet client = new GreeterClient('http://localhost:51318');\n\ntry {\n  let response = await HelloRequest({ name: 'Test name' });\n  console.log('got stuff from grpc', res.getMessage());\n} catch (e) {\n  console.log(e);\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackify%2Fswift-web-grpc-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackify%2Fswift-web-grpc-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackify%2Fswift-web-grpc-example/lists"}