{"id":13726235,"url":"https://github.com/FabienHenon/bs-remotedata","last_synced_at":"2025-05-07T21:31:43.789Z","repository":{"id":143654755,"uuid":"144713204","full_name":"FabienHenon/bs-remotedata","owner":"FabienHenon","description":"RemoteData and WebData to use with bs-fetch for BuckleScript","archived":false,"fork":false,"pushed_at":"2019-01-29T09:02:21.000Z","size":112,"stargazers_count":18,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T20:03:35.178Z","etag":null,"topics":["bucklescript","http","ocaml","reason","reasonml","remotedata","webdata"],"latest_commit_sha":null,"homepage":null,"language":"OCaml","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/FabienHenon.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-14T11:50:35.000Z","updated_at":"2020-07-15T04:04:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"222fab4a-64f2-49b1-b9cc-a3bca2586fac","html_url":"https://github.com/FabienHenon/bs-remotedata","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fbs-remotedata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fbs-remotedata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fbs-remotedata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabienHenon%2Fbs-remotedata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FabienHenon","download_url":"https://codeload.github.com/FabienHenon/bs-remotedata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224558323,"owners_count":17331331,"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":["bucklescript","http","ocaml","reason","reasonml","remotedata","webdata"],"created_at":"2024-08-03T01:02:56.526Z","updated_at":"2024-11-14T16:33:29.852Z","avatar_url":"https://github.com/FabienHenon.png","language":"OCaml","funding_links":[],"categories":["OCaml"],"sub_categories":[],"readme":"# bs-remotedata\n\n`RemoteData` and `WebData` to use with `bs-fetch` and `bs-json` for BuckleScript\n\n![Test status](https://travis-ci.org/FabienHenon/bs-remotedata.svg?branch=master)\n\n`RemoteData.t` is a simple variant type that allows you to store a data that can have 4 potential states:\n\n* `Success('a)`: your data has been successfully retrieved and stored\n* `Failure('e)`: your data could not be retrieved\n* `Loading`: your data is beeing fetched\n* `NotAsked`: you didn't fetch your data yet\n\nThis type provides you many usefull functions to handle your data: `map`, `andThen`, `withDefault`, `fromOption`, `fromResult`, `fromPromise`, ...\n\nThe main goal for this type is to be used for HTTP requests. That's where `WebData` comes into play.\n`WebData.t` is a `RemoteData.t` type but with the error type specified as a `WebData.error`. The `WebData` module provides some usefull functions to fetch data from API and convert it to a `WebData.t`. You can even provide your own _Json_ decoder to convert the result of your API call to a `WebData.t` of any type you want/need.\n\n## Example\n\n```reason\ntype person = {\n  age: int,\n  name: string\n};\n\nmodule Decode = {\n  let personDecoderExn = json =\u003e\n    Json.Decode.{\n      age: json |\u003e field(\"age\", int),\n      name: json |\u003e field(\"name\", string)\n    };\n    \n  let personDecoder = json =\u003e\n    try (Belt.Result.Ok(personDecoderExn(json))) {\n    | Json.Decode.DecodeError(err) =\u003e Belt.Result.Error(err)\n    };    \n};\n\n/* At app launch say you set your data state to `NotAsked` */\nlet data: WebData.t(person) = RemoteData.NotAsked;\n\n/* You received an event and you need to retrieve your data */\nlet data: WebData.t(person) = RemoteData.Loading;\n\nFetch.fetch(\"http://my-api\")\n|\u003e WebData.fromResponse(Decode.personDecoder)\n|\u003e Js.Promise.then_(data =\u003e {\n  /* Here your data is still a WebData.t(person) and will be\n    either Success(person), or Failure(httpError) */\n});\n```\n\n## Installation\n\n```\nnpm install --save bs-remotedata\n```\nThen add `bs-remotedata` to `bs-dependencies` in your `bsconfig.json`:\n```\n{\n  ...\n  \"bs-dependencies\": [\"bs-remotedata\"]\n}\n```\n\n## Documentation\n\nFor the moment, please see the interface files:\n\n* [RemoteData](src/RemoteData.rei)\n* [WebData](src/WebData.rei)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabienHenon%2Fbs-remotedata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFabienHenon%2Fbs-remotedata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabienHenon%2Fbs-remotedata/lists"}