{"id":17049097,"url":"https://github.com/toddself/restormify","last_synced_at":"2025-04-12T16:13:08.828Z","repository":{"id":19114920,"uuid":"22343817","full_name":"toddself/restormify","owner":"toddself","description":"Expose your node-orm2 models as a REST interface with node-restify","archived":false,"fork":false,"pushed_at":"2014-10-29T13:20:54.000Z","size":404,"stargazers_count":9,"open_issues_count":7,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T16:08:56.630Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toddself.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":"2014-07-28T13:41:44.000Z","updated_at":"2019-07-11T20:52:01.000Z","dependencies_parsed_at":"2022-08-25T14:11:13.263Z","dependency_job_id":null,"html_url":"https://github.com/toddself/restormify","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frestormify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frestormify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frestormify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddself%2Frestormify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toddself","download_url":"https://codeload.github.com/toddself/restormify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248594136,"owners_count":21130314,"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":[],"created_at":"2024-10-14T09:53:50.759Z","updated_at":"2025-04-12T16:13:08.791Z","avatar_url":"https://github.com/toddself.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build status](https://secure.travis-ci.org/toddself/restormify.png)](http://travis-ci.org/toddself/restormify)\n\n# REST-ORM-ify\nA package designed to easily expose [node-orm2](https://github.com/dresende/node-orm2) models as REST interface using [node-restify](https://github.com/mcavage/node-restify). Requires the use of the `restify.bodyParser` middleware.\n\nThe API will generate a [HAL-compliant](http://stateless.co/hal_specification.html) REST interface allowing for abitrary content association and better automation for interacting with objects.\n\nThis has been tested against:\n\n    \"orm\": \"~2.1.17\",\n    \"restify\": \"~2.8.1\",\n\n## Installation\n\n```\nnpm i restormify\n```\n\n## Usage\n\n```js\nvar restify = require('restify');\nvar orm = require('orm');\nvar restormify = require('restormify');\n\nvar server = restify.createServer();\nserver.use(restify.bodyParser());\norm.connect('some/db/string', function(err, db){\n  db.define('todo', {\n    task: String,\n    completed: Boolean,\n    deleted: {type: 'boolean', serverOnly: true},\n    hiddenValue: {type: text, serverOnly: true}\n  });\n  db.sync('models', function(){\n\n    restormify({\n      db: db,\n      server: server,\n      apiBase: 'api',\n      deletedColumn: 'deleted',\n      allowAccess: function(req, method, resourceName, resourceId){\n        return true;\n      }\n    }, function(err, relationsModel){\n      server.listen(3000);\n    });\n  });\n});\n```\n\nThis will expose `todo` as `/api/todo` responding to:\n\n* `GET /api/todo`\n* `GET /api/todo/[id]`\n* `POST /api/todo`\n* `PUT /api/todo/[id]`\n* `PATCH /api/todo/[id]`\n* `DELETE /api/todo/[id]`\n\n```\n\u003e curl -X POST -H 'Content-type: application/json' -d '{\"task\": \"Write tests\", \"completed\": false}' myapi.com/api/todo\n\n{\n  \"id\": 1,\n  \"task\": \"Write tests\",\n  \"completed\": false,\n  \"_links\": {\n    \"self\": {\n      \"href\": \"/api/todo/1\",\n      \"type\": \"todo\"\n    },\n    \"associations\": {\n      \"href\": \"/api/todo/1/associations\"\n    },\n    \"associate\": {\n      \"href\": \"/api/todo/1/{associatioName}\",\n      \"templated\": \"true\"\n    }\n  }\n}\n```\n\nIt will also allow you to associate content, and retrieve those associations, as well as information about the resource being retrieved.\n\n```\ncurl -X POST -H 'Content-type: application/json' myapi.com/api/todo/1/assocate/todo -d '{\"id\": 1,\"task\": \"Write tests\",\"completed\": false,\"_links\": {\"self\": {\"href\": \"/api/todo/1\",\"type\": \"todo\"},\"associations\": {\"href\": \"/api/todo/1/associations\"},\"associate\": {\"href\": \"/api/todo/1/{associatioName}\",\"templated\": \"true\"}}}'\n\n{\n  todo: [\n    {\n      \"id\": 1,\n      \"task\": \"Write tests\",\n      \"completed\": false,\n      \"_links\": {\n        \"self\": {\n          \"href\": \"/api/todo/1\",\n          \"type\": \"todo\"\n        },\n        \"associations\": {\n          \"href\": \"/api/todo/1/associations\"\n        },\n        \"associate\": {\n          \"href\": \"/api/todo/1/{associatioName}\",\n          \"templated\": \"true\"\n        }\n      }\n    }\n  ]\n}\n```\n\n## API\n\nThe default options are:\n\n`restormify(opts, callback)`\n\n### `opts`\n\n```js\n{\n    apiBase: 'api',\n    deletedColumn: 'deleted',\n    allowAccess: function(){\n      return true;\n    },\n    logger: server.logger\n}\n```\n\n`options.apiBase`: what all requests to your API will be prefixed with.\n`options.deletedColumn`: the name of the column to flag a piece of content as deleted. If set to `false` it **will destroy data in your database**\n`options.allowAccess`: This method is called on each request. Returning `false` will return `401: Not authorized` to the client. It is passed in the restify `req` object, the name of the resource (and any ID), along with the HTTP method.\n`options.logger`: Specify a [bunyan](https://github.com/trentm/node-bunyan) logger function to use. Defaults to `default` (which uses the logger available from restify object), `false` will disable logging.\n\n### `callback(err, relationsModel)`\n\nWhen the system has finished initlizing it'll call this with the db instance to the relations table or an error if any.\n\n## Tests and Coverage\n\n`npm test`\n`npm test-coverage`\n\n## License\nrestormify is ©2014 Todd Kennedy. Available for use under the [MIT License](LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddself%2Frestormify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoddself%2Frestormify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddself%2Frestormify/lists"}