{"id":18425819,"url":"https://github.com/dwayne/elm-json-rpc","last_synced_at":"2025-04-13T18:18:34.064Z","repository":{"id":62878541,"uuid":"555323740","full_name":"dwayne/elm-json-rpc","owner":"dwayne","description":"JSON-RPC 2.0 for Elm.","archived":false,"fork":false,"pushed_at":"2024-04-22T20:52:53.000Z","size":95,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T08:17:13.720Z","etag":null,"topics":["elm","json","json-rpc","json-rpc2","rpc"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/dwayne/elm-json-rpc/latest/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwayne.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":"2022-10-21T11:02:57.000Z","updated_at":"2024-04-22T20:52:57.000Z","dependencies_parsed_at":"2022-11-08T10:00:29.991Z","dependency_job_id":null,"html_url":"https://github.com/dwayne/elm-json-rpc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwayne%2Felm-json-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwayne%2Felm-json-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwayne%2Felm-json-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwayne%2Felm-json-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwayne","download_url":"https://codeload.github.com/dwayne/elm-json-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758423,"owners_count":21156958,"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":["elm","json","json-rpc","json-rpc2","rpc"],"created_at":"2024-11-06T05:05:54.544Z","updated_at":"2025-04-13T18:18:34.045Z","avatar_url":"https://github.com/dwayne.png","language":"Elm","readme":"# Elm JSON-RPC\n\nA [JSON-RPC 2.0](https://www.jsonrpc.org/specification) library for Elm. You can\nuse it to send\n[JSON-RPC requests](https://www.jsonrpc.org/specification#request_object)\nover HTTP.\n\n## Creating requests\n\nA request with no parameters:\n\n```elm\nimport Json.Decode as JD\nimport JsonRpc\n\ncurrentTime : JsonRpc.Request String\ncurrentTime =\n    { method = \"currentTime\"\n    , params = JsonRpc.noParams\n    , result = JD.string\n    }\n```\n\nA request with positional parameters:\n\n```elm\nimport Json.Encode as JE\n\nadd : Int -\u003e Int -\u003e JsonRpc.Request Int\nadd a b =\n    { method = \"add\"\n    , params =\n        JsonRpc.positionalParams\n            [ JE.int a\n            , JE.int b\n            ]\n    , result = JD.int\n    }\n```\n\nA request with named parameters:\n\n```elm\nsubtract : Float -\u003e Float -\u003e JsonRpc.Request Float\nsubtract minuend subtrahend =\n    { method = \"subtract\"\n    , params =\n        JsonRpc.namedParams\n            [ ( \"minuend\", JE.float minuend )\n            , ( \"subtrahend\", JE.float subtrahend )\n            ]\n            -- No optional parameters\n            []\n    , result = JD.float\n    }\n\nintToString : Int -\u003e Maybe Int -\u003e JsonRpc.Request String\nintToString n maybeBase =\n    { method = \"intToString\"\n    , params =\n        JsonRpc.namedParams\n            [ ( \"n\", JE.float minuend )\n            ]\n            -- 1 optional parameter\n            --\n            -- If maybeBase is Nothing then\n            -- the named parameter \"base\"\n            -- isn't sent over the wire\n            [ ( \"base\", Maybe.map JE.int maybeBase )\n            ]\n    , result = JD.string\n    }\n```\n\n## Sending requests\n\n### Basics\n\n```elm\nrpcUrl = \"https://json-rpc.example.com\"\n\ntype Msg\n    = GotCurrentTime (Result JsonRpc.Error String)\n\nJsonRpc.send rpcUrl GotCurrentTime currentTime\n```\n\nThis will send the JSON-RPC request:\n\n```json\n{\n    \"jsonrpc\": \"2.0\",\n    \"method\": \"currentTime\",\n    \"params\": [],\n    \"id\": 1\n}\n```\n\nover HTTP to the endpoint `https://json-rpc.example.com`.\n\n### Changing the request identifier\n\nTo change the request identifier use `sendWithId`.\n\nUse an integer identifier:\n\n```elm\nJsonRpc.sendWithId\n    rpcUrl\n    GotCurrentTime\n    (JsonRpc.intId 2)\n    currentTime\n```\n\nThe corresponding JSON-RPC request will be:\n\n```json\n{\n    \"jsonrpc\": \"2.0\",\n    \"method\": \"currentTime\",\n    \"params\": [],\n    \"id\": 2\n}\n```\n\nUse a string identifier:\n\n```elm\nJsonRpc.sendWithId\n    rpcUrl\n    GotCurrentTime\n    (JsonRpc.stringId \"abc123\")\n    currentTime\n```\n\nThe corresponding JSON-RPC request will be:\n\n```json\n{\n    \"jsonrpc\": \"2.0\",\n    \"method\": \"currentTime\",\n    \"params\": [],\n    \"id\": \"abc123\"\n}\n```\n\n### Want to change the HTTP settings?\n\nTake a look at `sendCustom`.\n\n## Handling errors\n\nA JSON-RPC request can fail in many ways. Suppose the `currentTime` RPC call\nfails then in our update function we can handle it as follows:\n\n```elm\nimport JsonRpc\n\nGotCurrentTime (Err error) -\u003e\n  case error of\n      JsonRpc.HttpError httpError -\u003e\n          -- There was an error trying to\n          -- reach the server.\n          ...\n\n      JsonRpc.UnexpectedStatus metadata body -\u003e\n          -- A successful HTTP status code\n          -- other than 200 was returned.\n          ...\n\n      JsonRpc.DecodeError jsonDecodeError -\u003e\n          -- The Response object returned\n          -- by the server was malformed.\n          ...\n\n      JsonRpc.MismatchedIds { requestId, responseId } -\u003e\n          -- The id of the Request object\n          -- is not the same as the id of\n          -- the Response object.\n          ...\n\n      JsonRpc.JsonRpcError { kind, code, message, maybeData, responseId } -\u003e\n          -- The RPC call encountered an error.\n          -- The maybeData field may contain\n          -- detailed error information as\n          -- defined by the server.\n          ...\n```\n\n## Examples\n\nThe `examples` directory contains:\n\n- An [Ethereum](https://ethereum.github.io/execution-apis/api-documentation/)\nexample based on `eth_chainId` and `eth_getBalance`.\n- A [RandomOrg](https://api.random.org/json-rpc/4/basic) example based on\n`generateIntegers`.\n\nTo play with the examples do the following:\n\n```bash\n$ nix-shell\n$ serve-examples\n```\n\nThen, open http://localhost:8000 in your browser and explore!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwayne%2Felm-json-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwayne%2Felm-json-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwayne%2Felm-json-rpc/lists"}