{"id":13555382,"url":"https://github.com/bergos/hydra-middleware","last_synced_at":"2025-07-28T23:05:10.138Z","repository":{"id":33124709,"uuid":"36763861","full_name":"bergos/hydra-middleware","owner":"bergos","description":null,"archived":false,"fork":false,"pushed_at":"2018-06-11T23:02:40.000Z","size":42,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-04T14:55:52.711Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/bergos.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}},"created_at":"2015-06-02T21:47:16.000Z","updated_at":"2024-07-27T12:31:29.000Z","dependencies_parsed_at":"2022-07-14T01:20:37.816Z","dependency_job_id":null,"html_url":"https://github.com/bergos/hydra-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bergos/hydra-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergos%2Fhydra-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergos%2Fhydra-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergos%2Fhydra-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergos%2Fhydra-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bergos","download_url":"https://codeload.github.com/bergos/hydra-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bergos%2Fhydra-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267600091,"owners_count":24113713,"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-07-28T02:00:09.689Z","response_time":68,"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":"2024-08-01T12:03:10.960Z","updated_at":"2025-07-28T23:05:10.099Z","avatar_url":"https://github.com/bergos.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","others"],"sub_categories":[],"readme":"# hydra-middleware\n\nMiddleware for [Hydra](http://www.hydra-cg.com/) hypermedia-driven Web APIs.\n\n## Usage\n\nThe package contains different middleware functions to publish the Hydra API and handle API request.\n\n### Classes\n\nAll API requests are handled by Hydra classes.\nAn existing class can be easily converted to a Hydra class by inheriting from the SimpleRDF class.\nPlease have a look at the [SimpleRDF documentation](https://github.com/simplerdf/simplerdf), if you are unfamiliar with that package.\nMethods can be attached directly to the class or properties.\nThe method names are the same as the lower case HTTP methods (e.g. `.get`, `.put`, ...).\n\n    // load the SimpleRDF class\n    var SimpleRDF = require('simplerdf/lite').SimpleRDF\n\n    // create the HydraClass and inherit from SimpleRDF\n    function HydraClass() {}\n\n    utils.inherits(HydraClass, SimpleRDF)\n\n    // attach the methods\n\n    HydraClass.prototype.get = function () {\n      return this\n    }\n\n    HydraClass.prototype.put = function (input) {\n       // handle SimpleRDF input object\n    }\n\n### API Header\n\nHydra requires an additional HTTP header that points to the [API Documentation](http://www.w3.org/ns/hydra/core#apiDocumentation).\nThis module adds the Link header.\nThe only parameter is the URL to the API Documentation.\n\n    var apiHeader = require('hydra-middleware/api-header')\n\n    app.use(apiHeader('/vocab')\n\n\nIf you also want to host the API Documentation in your application you can use the `rdf-serve-static` package.\n\n    var formats = require('rdf-formats-common')()\n    var serve = require('rdf-serve-static')\n\n    app.use(serve('folder-that-contains-the-vocab-file', formats))\n\n### Object\n\nTo host single instances of Hydra classes the `object` middleware can be used.\nIt requires the object instance and the SimpleRDF context, that should be used for the requests.\n\n    var object = require('hydra-middleware/object')\n\n    app.use('/path-to-object', object(instance, context))\n\n### Factory\n\nThe `factory` middlware can be used if you don't want to store all Hydra objects in memory.\nThe factory function is called on each request.\nIt should return the Hydra object for the requested IRI.\n\n    var factory = require('hydra-middleware/factory')\n\n    function objectBuilder (iri) {\n      return instance\n    }\n\n    app.use(factory(objectBuilder)\n\n## Examples\n\nThe examples folder contains examples how to use the middleware.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbergos%2Fhydra-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbergos%2Fhydra-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbergos%2Fhydra-middleware/lists"}