{"id":20331160,"url":"https://github.com/comcast/hypergard","last_synced_at":"2025-04-11T21:07:33.898Z","repository":{"id":48874706,"uuid":"127325271","full_name":"Comcast/hypergard","owner":"Comcast","description":"A JavaScript client for HAL APIs with support for forms","archived":false,"fork":false,"pushed_at":"2020-01-22T20:15:42.000Z","size":134,"stargazers_count":7,"open_issues_count":2,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-11T21:07:31.633Z","etag":null,"topics":["hal","hypermedia","hypermedia-client","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Comcast.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-29T17:30:57.000Z","updated_at":"2023-11-28T16:30:00.000Z","dependencies_parsed_at":"2022-08-19T14:00:58.792Z","dependency_job_id":null,"html_url":"https://github.com/Comcast/hypergard","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comcast%2Fhypergard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comcast%2Fhypergard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comcast%2Fhypergard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Comcast%2Fhypergard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Comcast","download_url":"https://codeload.github.com/Comcast/hypergard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480434,"owners_count":21110937,"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":["hal","hypermedia","hypermedia-client","javascript"],"created_at":"2024-11-14T20:19:01.887Z","updated_at":"2025-04-11T21:07:33.857Z","avatar_url":"https://github.com/Comcast.png","language":"JavaScript","readme":"# HyperGard\n\n[![Build Status](https://travis-ci.org/Comcast/hypergard.svg?branch=master)](https://travis-ci.org/Comcast/hypergard)\n\nJavascript client for HAL APIs, with support for Hypermedia Forms\n\n\n## Installation\n\nWhen using [npm](https://www.npmjs.com/)\n\n```bash\nnpm install --save hypergard\n```\n\n## Usage\n\n### Initialize HyperGard instance\n```javascript\nconst HOMEPAGE_ENDPOINT = 'https://hypermedia-endpoint.com/'\nconst HalApi = new HyperGard(HOMEPAGE_ENDPOINT, {});\n```\n\n### Fetch Homepage\n```javascript\nconst homepageResource = await HalApi.fetchHomepage();\n```\n\n### Options\n\n#### `cacheHomepage`\n\nDefault value: `false`\n\nDetermines whether to keep locally closed over reference to homepage response, since the Homepage resource should be highly cache-able by Hypermedia standards.\n\n#### `preloadHomepage`\n\nDefault: `true`\n\nAuto-fetch homepage endpoint on initialization of HyperGard object.\n\n#### `xhr`\n\nNetwork request that will be passed along to [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).\n\nAdditionally `hypergard` implements a timeout around any network fetch, which will default to `60000` milliseconds\n\n```js\n{\n  // Headers to be added to each network fetch\n  headers: {\n    ['X-Custom-Header']: \"value\",\n  }\n  // Timeout period in milliseconds\n  timeout: 2000,\n}\n```\n\n#### `applyMiddlewareStack`\n\nAllows you to pass an array of middleware function to wrap around each fetch.\n\nEach middleware function should:\n* Have a method signature with arguments `url`, `options`, and `next`\n* Return the remaining stack `return next(url, options)` so the promise chain isn't broken\n\n#### Example of Middleware for accessing calls before fetch. (Replaces `beforeFetch` and `uniqueFetchHeaders` functionality)\n```\nfunction setCustomHeader(url, options, next) {\n  var newOptions = Object.assign({}, options, {\n    headers: {\n      'X-MoneyTrace': 'hey nowwwww',\n    }\n  });\n\n  // Call next piece of middleware\n  return next(url, newOptions);\n}\n```\n\n#### Example of Middleware for accessing calls after fetch  (Replaces `afterFetchSuccess` and `afterFetchFailure` functionality)\n```\nfunction loggerMiddleware(url, options, next) {\n  // Call next piece of middleware\n  var promiseChain = next(url, options);\n\n  // Log any 401\n  promiseChain.catch(function(error) {\n      if (error.status === '401') {\n        mockLogger.log('Unauthorized', {error: error});\n      }\n    })\n\n  // Return un-caught promise chain\n  return promiseChain;\n}\n```\n\n#### Example of Applying middleware stack\n\nMiddleware can be applied to an initialized `HyperGard` object, and will be executed based on order of array.\n\n```\nHalApi.applyMiddlewareStack([\n  setCustomHeader,\n  loggerMiddleware,\n]);\n```\n\n## Running Tests\n\n### Install Dependencies\n\n```\n$ npm run setup\n```\n\n### Running tests to manually validate a patchset\n\n```\n$ npm test\n```\n\n### Running tests during development\n\n```\n$ gulp test\n```\n\nThat `gulp test` command will load up Chrome. Click the \"Debug\" button and then open the JavaScript Console to see the test results. You can also use `console` methods to be able to debug your tests.\n\nNote that if you make a code change, you cannot simply reload http://localhost:8080/debug.html in Chrome. You have to stop the `gulp test` process with `Control+C` and then rerun the command (there's probably a better way to handle that, but it does the job for now).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomcast%2Fhypergard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomcast%2Fhypergard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomcast%2Fhypergard/lists"}