{"id":18389736,"url":"https://github.com/proloser/resteasy","last_synced_at":"2025-04-07T02:34:42.813Z","repository":{"id":2973868,"uuid":"3989204","full_name":"ProLoser/RESTeasy","owner":"ProLoser","description":"Node.JS Easy 3rd party OAuth \u0026 REST API Consumer","archived":false,"fork":false,"pushed_at":"2018-09-20T15:34:42.000Z","size":57,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T07:45:03.259Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://vimeo.com/proloser/resteasy","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"h5bp/Front-end-Developer-Interview-Questions","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProLoser.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":"2012-04-11T02:00:28.000Z","updated_at":"2022-01-28T20:31:49.000Z","dependencies_parsed_at":"2022-08-27T12:02:25.142Z","dependency_job_id":null,"html_url":"https://github.com/ProLoser/RESTeasy","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/ProLoser%2FRESTeasy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProLoser%2FRESTeasy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProLoser%2FRESTeasy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProLoser%2FRESTeasy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProLoser","download_url":"https://codeload.github.com/ProLoser/RESTeasy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247583551,"owners_count":20962057,"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-11-06T01:44:17.762Z","updated_at":"2025-04-07T02:34:37.803Z","avatar_url":"https://github.com/ProLoser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RESTeasy\n\u003e Make consuming RESTful apis **waaaaay** easier in Node.js\n\n### [New Video Tutorial!](https://vimeo.com/proloser/resteasy)\n\nEver notice how all of these APIs seem to have a high degree of consistency? They're just a bunch of URLs that accept different parameters you pass to it. So the thing is what's the point of creating a lib for each and every API and endpoint, making each url call involve a different class or method name? This means that in addition to learning the API you have to learn the lib API too. And what happens if the API updates? You're stuck waiting for the lib to incorporate the changes before you can actually leverage the new features.\n\nSo with _so much_ repetition from one API to another, I built a way to 'map' APIs. This means that updating and adding new APIs is ridiculously easy, and the only documentation you need to refer to is the native APIs, and even _that_ is kept to a minimum. All methods calls are extremely simple and consistent. Just specify the CRUD action, the resource name and pass the parameters you have available to you. The mapper will figure out what url it needs to use to get the job done, leaving you to make much more versatile code without knowing every nuance of every API.\n\n## Installation\n\n### Step 0: Require (obviously)\n\n```bash\n$ npm install resteasy\n```\n\n```javascript\nvar resteasy = require('resteasy');\n```\n\n### Step 1: Instantiate\n\n* __First param__ is the name of the provider OR a path to your own provider file.\n* __Second param__ is an object containing a `login` key (appId) and a `pass` key (appSecret). You can optionally pass the `oauth_token` and `oauth_token_secret` if you stored it and want to reuse the session\n\n```javascript\n// Instantiate an instance with config values\nvar keys = { login: '[appId]', pass: '[appSecret]' };\n//You must pass the full URL to where the callback is located\nvar callbackUrl = 'url';\n// var provider = resteasy('./providers/myprovider', ...); \nvar github = resteasy('resteasy/lib/providers/github', keys, callbackUrl);  \n```\n\n### Step 2: Authenticate\n\n```\ngithub.connect();\n```\n\n...redirects user to API for authentication which then forwards to callbackUrl...\n\n```javascript\n// Needs the node.js req object\ngithub.callback(req, function(error, oauth_token, oauth_token_secret, additionalParameters){\n  // Store auth credentials\n});\n```\n\n### Step 3: Querying\n\nYou can either use the general-purpose `github.request()` function to build your own queries if you are too lazy to \nsupplement a provider, but the preferred method is as follows:\n\n```javascript\nvar tokens = {\n  oauth_token: [your stored token],\n  oauth_token_secret: [your stored token secret]\n};\ngithub.read(tokens, 'repos', { user: 'ProLoser' },  function(err, data, res){\n  // `data` contains API response\n});\n```\n\nThe syntax is identical for `.create()`, `.update()`, and `.del()`. The provider map will be searched until a path with all\nof the REQUIRED params are matched is found. It will then proceed to use that endpoint.\n\n## LinkedIn Notes\nhttp://developer.linkedin.com/documents/profile-api  \nYou may need to pass fields, to get back the desired data.  \nTo do this create an object and pass true for every field type you want.  \n\n```javascript\nvar setFields = {\n\t'first-name' : true,\n\t'last-name' : true,\n\t'positions' : true,\n\t'educations' : true\n};\n```\n\n## Expanding Functionality\n\nAll it takes to add your own provider is a hashmap containing the specific API's endpoints in an organized manner.\n\nTo refer to your provider, just pass the path as the first argument (`github` above) as if you were passing it directly to `require`.\n\nUse this template and check out the other providers for examples:\n\n```javascript\nmodule.exports = {\n  // Contains base urls\n  hosts : {\n    oauth : // Base URL used for all OAuth requests. Ex: 'https://github.com/login/oauth'\n    rest : // Base URL used for all API requests. Ex: 'https://api.github.com'\n  },\n  // OAuth Configuration and paths. Usually appended to hosts.oauth url\n  oauth : {\n    version : // OAuth version. Ex: '1.0' or '2.0'\n    authorize : // Path to 'authorize' endpoint. Ex: A URI of https://github.com/login/oauth/user/authorize would be just 'user/authorize'\n    request : // Path to 'requestToken' endpoint\n    access : // Path to 'access_token' endpoint \n    login : // Path to 'authenticate' endpoint. Similar to authorize, just auto-redirects\n    logout : // Path to 'invalidateToken' endpoint\n  },\n  // CRUD - Read endpoints\n  read : {\n    // The 'section' or 'resource' name. Should be identical to the API's resource name\n    repos : [\n      // An array of endpoints going in order of SMALLER # of required params (or 0 / all optional) to the HIGHEST # of required params\n      {\n        // Path to endpoint. Can include colon-prefixed tokens that match keys in the params object. Appended to hosts.rest url\n        path : 'user/repos',\n        // Optional array of REQUIRED params (some endpoints don't need any)\n        required : [],\n        // Optional array of OPTIONAL (whitelisted) params that are also added to the request and/or substituted as tokens\n        optional : [\n          'type' // all, owner, public, private, member. Default: all\n        ]\n      },\n      {\n        path : 'repos/:user/:repo',\n        required : [\n          'user',\n          'repo'\n        ]\n        optional : [\n          'format',\n          'sortBy'\n        ]\n      }\n    ],\n    users : [ ... ]\n  },\n  // CRUD - Write endpoints\n  create : { ... },\n  // CRUD - Update endpoints\n  update: { ... },\n  // CRUD - Delete endpoints\n  'delete': { ... },\n  // An optional callback function to be executed just before any query is fired for API-specific massaging\n  prepQuery : function(query) {\n    return query;\n  },\n  // An optional callback function to be executed just before redirecting to connect for auth. Passes a redirectUrl for OAuth v1.0 and a params object for OAuth v2.0\n  prepConnect : function([redirectUrl | params], keys, scope) {\n    return [redirectUrl | params];\n  },\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproloser%2Fresteasy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproloser%2Fresteasy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproloser%2Fresteasy/lists"}