{"id":17659736,"url":"https://github.com/raphamorim/kenobi","last_synced_at":"2025-07-18T09:38:33.413Z","repository":{"id":20467146,"uuid":"23744614","full_name":"raphamorim/kenobi","owner":"raphamorim","description":"Render objects for view engines or static html","archived":false,"fork":false,"pushed_at":"2015-10-14T07:36:10.000Z","size":287,"stargazers_count":8,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T02:36:25.706Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/kenobi","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/raphamorim.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-09-06T20:29:48.000Z","updated_at":"2024-11-17T10:40:28.000Z","dependencies_parsed_at":"2022-07-31T20:48:08.096Z","dependency_job_id":null,"html_url":"https://github.com/raphamorim/kenobi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Fkenobi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Fkenobi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Fkenobi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphamorim%2Fkenobi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raphamorim","download_url":"https://codeload.github.com/raphamorim/kenobi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242980783,"owners_count":20216283,"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-23T16:08:07.764Z","updated_at":"2025-03-11T05:33:15.071Z","avatar_url":"https://github.com/raphamorim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kenobi\n\n\u003e Render external objects and array in view engines\n\n[![NPM Version](https://img.shields.io/npm/v/express.svg?style=flat)](https://www.npmjs.org/package/kenobi)\n[![Build Status](https://api.travis-ci.org/raphamorim/kenobi.svg)](https://travis-ci.org/raphamorim/kenobi)\n\n## Install\n\n\tnpm install kenobi\n\n## How it works\n\nIn this example we are using the product hunter's API.\n\nThe options variable sets the request.\n\n\tvar options = {\n    \turl: \"https://api.producthunt.com/v1/posts\",\n    \tauth: {\n      \t\tbearer: \"XXXXXXX\"\n    \t},\n    \theaders: {\n        \t'User-Agent': 'request'\n    \t},\n \t\tmethod: \"GET\",\n    \tjson: true,\n    \ttimeout: 10000\n  \t};\n\nAfter it is sent as the first parameter, after is set the page view path.\n\n  \tkenobi(options, '/views/index.ejs', function(page){\n  \t\tres.end(page); // Response\n  \t});\n\nDetail: You can sent only the url `string` instead request `object`. However\nthe request body act as default ([see default properties](#request-params)), ex:\n\n    kenobi('https://api.producthunt.com/v1/posts', '/views/index.ejs', function(page){\n      res.end(page); // Response\n    });\n\nSo, then we can treat the object in view. Then a global object is returned. Accessed by the name of **body**. See how it happens in ejs example:\n\n\t\u003cbody\u003e\n\n\t\u003c% if (_.posts.length) { %\u003e\n\t\t\u003cul\u003e\n\t\t\t\u003c% _.posts.forEach(function(post){ %\u003e\n\t\t\t\t\u003cli\u003e\u003c%= post.name %\u003e\u003c/li\u003e\n\t\t\t\u003c% }) %\u003e\n\t\t\u003c/ul\u003e\n\t\u003c% } %\u003e\n\n\t\u003c/body\u003e\n\n\n## Get response without view\n\nFor return only response object:\n\n    kenobi(options, function(response, err){\n  \t    if (err) res.end(err);\n        res.send(response);\n     });\n\n\n## Send only a local object (without external request) and render in template:\n\nUse request false\n\n    var object = {name: 'luke', request: false};\n\n    kenobi(object, pathTofile, function(page, response, err){\n        // For local objects cases, response always be null\n\n        if (err) res.end(err);\n        res.end(page);\n    });\n\n\n## Using HTML instead template option:\n\nThis option is still very limited, the current version is still not possible to make operations and comparisons with the variables passed to the html. Ex:\n\n**anything.js**\n\n    var object = {name: 'Obi Wan'};\n\n    kenobi(object, 'index.html', function(page, response, err){\n        if (err) res.end(err);\n        res.send(page);\n    });\n\n**index.html**\n\n    ...\n    \u003cbody\u003e\n      \u003ch1\u003e{{name}}\u003c/h1\u003e\n    \u003c/body\u003e\n    ...\n\n\n## Callback Return\n\npage `String` = result of rendering\n\nresponse `Object` = response from request\n\nerror `Object` = error from operation, if not exist must be `null`\n\n  \tkenobi(options, pathTofile, function(page, response, err){\n      \t\tconsole.log(\"Response: \" + response);\n      \t\tres.send(page);\n  \t});\n\nIn Response Object, you can access some data like statusCode, body...\n\n\n## Template Examples\n\nIt sent an object to the template with the primary key accessed by an underscore. Examples:\n\n**Ejs:**\n\n\t\u003c% _.posts.forEach(function(post){ %\u003e\n\t\t\u003cli\u003e\u003c%= post.name %\u003e\u003c/li\u003e\n\t\u003c% }) %\u003e\n\n**Jade:**\n\n\teach post in _.posts\n    \tli= post.name\n\n\n## Request Object (optional params)\n\nThe first argument can be either a `url` or an object. The only required option is `uri`, all others are optional.\n\n- `uri` || `url` - fully qualified uri or a parsed url object from `url.parse()`\n\n- `qs` - object containing querystring values to be appended to the `uri`\n\n- `method` - http method (default: `\"GET\"`)\n\n- `headers` - http headers (default: `{}`)\n\n- `body` - entity body for PATCH, POST and PUT requests. Must be a `Buffer` or `String`.\n\n- `form` - when passed an object or a querystring, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header. When passed no options, a `FormData` instance is returned (and is piped to request).\n\n- `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional).  See documentation above.\n\n- `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header.  Additionally, parses the response body as JSON.\n\n- `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.\n\n- `followRedirect` - follow HTTP 3xx responses as redirects (default: `true`). This property can also be implemented as function which gets `response` object as a single argument and should return `true` if redirects should continue or `false` otherwise.\n\n- `followAllRedirects` - follow non-GET HTTP 3xx responses as redirects (default: `false`).\n\n- `maxRedirects` - the maximum number of redirects to follow (default: `10`).\n\n- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`.\n\n- `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request.\n\n- `proxy` - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the `url` parameter (by embedding the auth info in the `uri`).\n\n- `oauth` - Options for OAuth HMAC-SHA1 signing. See documentation above.\n\n- `aws` - `object` containing AWS signing information. Should have the properties `key`, `secret`. Also requires the property `bucket`, unless you’re specifying your `bucket` as part of the path, or the request doesn’t use a bucket (i.e. GET Services)\n\n\n## View Engines\n\n- [Ejs](https://github.com/visionmedia/ejs)\n- [Jade](https://github.com/visionmedia/jade)\n\n## Who's using Kenobi\n\n- [3days](http://3days.com.br)\n- [ShotHunt](http://shothunt.herokuapp.com)\n\nYou're using Kenobi too? Let me know :)\n\n## History\n\nSee [Changelog](docs/changelog.md) for more details.\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -m 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## License\n\nMIT License © [Raphael Amorim](https://github.com/raphamorim)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphamorim%2Fkenobi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraphamorim%2Fkenobi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphamorim%2Fkenobi/lists"}