{"id":18941471,"url":"https://github.com/mchmarny/godapr","last_synced_at":"2026-05-01T04:35:33.706Z","repository":{"id":77051485,"uuid":"255396837","full_name":"mchmarny/godapr","owner":"mchmarny","description":"Simple dapr HTTP client library ","archived":false,"fork":false,"pushed_at":"2020-06-14T16:28:27.000Z","size":278,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-31T22:42:56.073Z","etag":null,"topics":["client","dapr","go","grpc","pubsub"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mchmarny.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-13T17:30:20.000Z","updated_at":"2020-11-12T14:09:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"27dc69ca-9b16-414d-94a9-82b68752065c","html_url":"https://github.com/mchmarny/godapr","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgodapr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgodapr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgodapr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Fgodapr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mchmarny","download_url":"https://codeload.github.com/mchmarny/godapr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239942598,"owners_count":19722328,"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":["client","dapr","go","grpc","pubsub"],"created_at":"2024-11-08T12:28:11.233Z","updated_at":"2026-03-23T21:30:16.665Z","avatar_url":"https://github.com/mchmarny.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# godapr (simple dapr HTTP client)\n\nDapr has gRPC and REST APIs. For `go`, there is an auto-generated [gRPC SDK](https://github.com/dapr/go-sdk) and the developers can also implement their own HTTP calls to the REST API. When invoking the dapr REST APIs there usually is lot's of redundant code building request, parsing responses, and dealing with traces. I create this client to simplify Dapr integrations and minimize code duplication.\n\n\u003e Note, I submitted a [PR](https://github.com/dapr/go-sdk/pull/18) with similar enhancements to the [go-sdk](https://github.com/dapr/go-sdk) already submitted [#18](https://github.com/dapr/go-sdk/pull/18)\n\n## Usage\n\nTo use `godapr` first get the library\n\n```shell\ngo get github.com/mchmarny/godapr/v1\n```\n\n### Create Client\n\nTo use `godapr` library in your code, first import it\n\n```go\nimport dapr \"github.com/mchmarny/godapr/v1\"\n```\n\nThen create a `godapr` client with the `dapr` server defaults\n\n```go\nclient := dapr.NewClient()\n```\n\nor if you need to specify non-default dapr port\n\n```go\nclient := dapr.NewClientWithURL(\"http://localhost:3500\")\n```\n\n### State\n\n#### Save Data\n\nTo save state using the the \"reasonable\" defaults:\n\n```go\nstate := \"my data\"\nerr := client.SaveState(ctx, \"store-name\", \"id-123\", state)\n```\n\nYou can also persist objects\n\n```go\nperson := \u0026Person{ Name: \"Example John\", Age: 35 }\nerr := client.SaveState(ctx, \"store-name\", \"id-123\", person)\n```\n\nFor more control, you can also create the `StateData` object\n\n```go\ndata := \u0026StateData{\n    Key: \"id-123\",\n    Value: person,\n    Options: \u0026StateOptions{\n        Consistency: \"eventual\",\n        Concurrency: \"first-write\",\n    },\n}\nerr := client.SaveStateWithData(ctx, \"store-name\", data)\n```\n\n#### Get Data\n\nTo get state data you can either use the client defaults (\"strong\" Consistency, \"last-write\" Concurrency)\n\n```go\ndata, err := client.GetState(ctx, \"store-name\", \"record-key\")\n```\n\nOr, for more control, define your own state options\n\n```go\nopt := \u0026StateOptions{\n    Consistency: \"eventual\",\n    Concurrency: \"first-write\",\n}\n\ndata, err := client.GetStateWithOptions(ctx, \"store-name\", \"record-key\", opt)\n```\n\n`data` contains the `[]byte` content retrieved from the state store\n\n#### Delete Data \n\nSimilarly with deleting, you can either use the defaults\n\n```go\nerr := client.DeleteState(ctx, \"store-name\", \"record-key\")\n```\n\nOr define your own state data object\n\n```go\nopt := \u0026StateOptions{\n    Consistency: \"eventual\",\n    Concurrency: \"first-write\",\n}\n\nerr := client.DeleteStateWithOptions(ctx, \"store-name\", opt)\n```\n\n### Events\n\nTo publish events to a topic you can pass instance of your own struct\n\n```go\nerr := client.Publish(ctx, \"topic-name\", person)\n```\n\nOr send the raw content in bytes \n\n```go\ndata := []byte(\"hi\")\nerr := client.PublishWithData(ctx, \"topic-name\", data)\n```\n\n### Binding\n\nSimilarly with binding, you can invoke binding without any data\n\n```go\nout, err := client.InvokeBinding(ctx, \"binding-name\", \"create\")\n```\n\nOr, with an instance of your own struct\n\n```go\nout, err := client.InvokeBindingWithIdentity(ctx, \"binding-name\", \"create\", person)\n```\n\nOr, for more control, with an instance of the `BindingData`\n\n\n```go\ndata := \u0026BindingData{\n    Data:      []byte(\"your content\"),\n    Operation: \"create\",\n    Metadata:  map[string]string{ \"k1\":\"v1\", \"k2\": \"v2\" },\n}\nout, err := client.InvokeBindingWithData(ctx, \"binding-name\", \"create\", data)\n```\n\n`out` contains the `[]byte` content returned by the binding \n\n### Service Invocation \n\n\nSimilarly with service to service invocation, you can invoke without any data\n\n```go\nout, err := client.InvokeService(ctx, \"service-name\", \"method-name\")\n```\n\nOr, with an instance of your own struct\n\n```go\nout, err := client.InvokeServiceWithIdentity(ctx, \"service-name\", \"method-name\", person)\n```\n\nOr, invoke it directly with your own content \n\n\n```go\ndata := []byte(\"your content\")\nout, err := client.InvokeServiceWithData(ctx, \"binding-name\", \"create\", data)\n```\n\n`out` contains the `[]byte` content returned by the service \n\n## Disclaimer\n\nThis is my personal project and it does not represent my employer. I take no responsibility for issues caused by this code. I do my best to ensure that everything works, but if something goes wrong, my apologies is all you will get.\n\n## License\nThis software is released under the [Apache v2 License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchmarny%2Fgodapr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmchmarny%2Fgodapr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchmarny%2Fgodapr/lists"}