{"id":24747897,"url":"https://github.com/codingitwrong/jsonapi-client","last_synced_at":"2025-10-25T23:32:52.737Z","repository":{"id":38841602,"uuid":"408127430","full_name":"CodingItWrong/jsonapi-client","owner":"CodingItWrong","description":"Zero-configuration JSON:API web service client","archived":false,"fork":false,"pushed_at":"2025-10-02T00:18:33.000Z","size":2589,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-08T10:56:12.166Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodingItWrong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-09-19T12:56:49.000Z","updated_at":"2025-10-02T00:18:35.000Z","dependencies_parsed_at":"2024-04-02T01:24:38.942Z","dependency_job_id":"43e5b937-2df4-48b8-95e6-e3ec0a65bbc6","html_url":"https://github.com/CodingItWrong/jsonapi-client","commit_stats":{"total_commits":433,"total_committers":10,"mean_commits":43.3,"dds":0.6304849884526559,"last_synced_commit":"cdfda7df859c9c9610451e73cf91a91c27dba79c"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/CodingItWrong/jsonapi-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodingItWrong%2Fjsonapi-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodingItWrong%2Fjsonapi-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodingItWrong%2Fjsonapi-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodingItWrong%2Fjsonapi-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodingItWrong","download_url":"https://codeload.github.com/CodingItWrong/jsonapi-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodingItWrong%2Fjsonapi-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281038650,"owners_count":26433634,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-01-28T05:18:04.684Z","updated_at":"2025-10-25T23:32:52.708Z","avatar_url":"https://github.com/CodingItWrong.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @codingitwrong/jsonapi-client\n\nA lightweight client for making requests to a [JSON:API](https://jsonapi.org/) service.\n\n- It doesn't attempt to provide a way to utilize every possible feature of JSON:API; instead, it offers a core set of functionality sufficient for most apps.\n- It doesn't attempt to abstract away the JSON:API object format; instead, it returns JSON:API data as-is.\n\n## Synopsis\n\n```javascript\nimport {ResourceClient} from '@codingitwrong/jsonapi-client';\n\nconst widgetClient = new ResourceClient({\n  name: 'widgets',\n  httpClient: axios.create(...),\n});\n\nwidgetClient.all()\n  .then(response =\u003e console.log(response.data));\n\nwidgetClient.create({\n  attributes: {\n    title: 'My Widget',\n  },\n});\n```\n\n## Installation\n\n```sh\n$ npm install --save @codingitwrong/jsonapi-client\n```\n\nor\n\n```sh\n$ yarn add @codingitwrong/jsonapi-client\n```\n\n`@codingitwrong/jsonapi-client` needs to be configured with an `httpClient` object that handles the requests and responses. The easiest way to do this is to provide an [`axios`](https://axios-http.com/) instance configured with your server's base URL and optionally any authentication info your server requires.\n\n```js\nimport axios from 'axios';\nimport {ResourceClient} from '@codingitwrong/jsonapi-client';\n\nconst token = 'FILL_ME';\n\nconst httpClient = axios.create({\n  baseURL: 'https://jsonapi-sandbox.herokuapp.com',\n  headers: {'Authentication': `Bearer ${token}`},\n});\nconst widgetClient = new ResourceClient({name: 'widgets', httpClient});\n\nwidgetClient.all()\n  .then(response =\u003e console.log(response.data));\n```\n\n## Usage\n\n### Reading Data\n\n#### all([{options}])\n\nTo retrieve all of the records for a resource, call the `all()` method. The method returns a promise that will resolve to the [JSON:API document](https://jsonapi.org/format/#document-structure) the server responded with:\n\n```javascript\nresourceClient.all()\n  .then(response =\u003e console.log(response.data));\n```\n\nNote that because the `response` is the full JSON:API document, the array of records is nested under the `data` key. This ensures you also have access to keys like `errors`, `meta`, and `included` when applicable.\n\n#### Options\n\nAll methods that return records (so, all but `delete()`) take an optional `options` named argument, consisting of an object of additional options to pass. Each key/value pair in the object is translated into a query string parameter key/value pair:\n\n```js\nresourceClient.all({\n  options: {\n    include: 'comments',\n    sort: '-createdAt',\n    'page[number]': 1,\n  },\n});\n\n// requests to widgets?include=comments\u0026sort=-createdAt\u0026page[number]=1\n```\n\n#### find({id, [options]})\n\nTo retrieve a single record by ID, call the `find()` method:\n\n```javascript\nresourceClient.find({id: 42})\n  .then(response =\u003e console.log(response.data));\n\n// requests to widgets/42\n```\n\n#### where({filter, [options]})\n\nTo filter/query for records based on certain criteria, use the `where` method, passing it an object of filter keys and values to send to the server:\n\n```javascript\nconst filter = {\n  category: 'whizbang',\n};\nresourceClient.where({filter})\n  .then(response =\u003e console.log(response.data));\n\n// requests to widgets?filter[category]=whizbang\n```\n\n#### related({parent, [options]})\n\nFinally, to load records related via JSON:API relationships, use the `related` method. A nested resource URL is constructed like `categories/27/widgets`.\n\n```javascript\nconst parent = {\n  type: 'category',\n  id: 27,\n};\n\nresourceClient.related({parent})\n  .then(response =\u003e console.log(response.data));\n\n// requests to categories/27/widgets\n```\n\nBy default, the name of the relationship on `parent` is assumed to be the same as the name of the other model: in this case, `widgets`. In cases where the names are not the same, you can explicitly pass the relationship name:\n\n```javascript\nconst parent = {\n  type: 'categories',\n  id: 27,\n};\n\nconst relationship = 'purchased-widgets';\n\nresourceClient.related({parent, relationship})\n  .then(response =\u003e console.log(response.data));\n\n// requests to categories/27/purchased-widgets\n```\n\n### Writing\n\n#### create({[attributes, relationships, options]})\n\nCreates a new record. Either the `attributes`, `relationships`, or both can be passed. You do not need to pass in the `type` as the `ResourceClient` already knows what `type` it is for:\n\n```js\nwidgetResource.create({\n  attributes: {\n    'name': 'My Widget',\n    'creation-date': '2018-10-07',\n  },\n});\n\n// POSTs to widgets\n```\n\n#### update({id, [attributes, relationships, options]})\n\nUpdates a record. Takes the `id` of the record and the `attributes` and/or `relationships` to update. No `type` argument is required, but if passed in it's ignored, so you can pass in a full record if you like.\n\n```js\nwidgetResource.update({\n  id: '42',\n  attributes: {\n    name: 'My Updated Widget',\n  },\n});\n\n// PATCHes to widgets/42\n```\n\n#### delete({id})\n\nDeletes the passed-in record. Only the `id` property is used, so you can pass either a full record or just the ID:\n\n```js\nwidgetResource.delete({id: 42});\n\n// DELETEs to widgets/42\n```\n\n## License\n\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingitwrong%2Fjsonapi-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodingitwrong%2Fjsonapi-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingitwrong%2Fjsonapi-client/lists"}