109 lines
11 KiB
JSON
109 lines
11 KiB
JSON
|
|
{
|
||
|
|
"_args": [
|
||
|
|
[
|
||
|
|
{
|
||
|
|
"raw": "rest-facade@^1.10.0",
|
||
|
|
"scope": null,
|
||
|
|
"escapedName": "rest-facade",
|
||
|
|
"name": "rest-facade",
|
||
|
|
"rawSpec": "^1.10.0",
|
||
|
|
"spec": ">=1.10.0 <2.0.0",
|
||
|
|
"type": "range"
|
||
|
|
},
|
||
|
|
"/home/jdaugherty/work/GT2/GT2-Android/node_modules/auth0"
|
||
|
|
]
|
||
|
|
],
|
||
|
|
"_from": "rest-facade@>=1.10.0 <2.0.0",
|
||
|
|
"_id": "rest-facade@1.10.1",
|
||
|
|
"_inCache": true,
|
||
|
|
"_location": "/rest-facade",
|
||
|
|
"_nodeVersion": "8.4.0",
|
||
|
|
"_npmOperationalInternal": {
|
||
|
|
"host": "s3://npm-registry-packages",
|
||
|
|
"tmp": "tmp/rest-facade-1.10.1.tgz_1509764117424_0.3721047551371157"
|
||
|
|
},
|
||
|
|
"_npmUser": {
|
||
|
|
"name": "ngonzalvez",
|
||
|
|
"email": "n.gonzalvez@outlook.com"
|
||
|
|
},
|
||
|
|
"_npmVersion": "5.3.0",
|
||
|
|
"_phantomChildren": {},
|
||
|
|
"_requested": {
|
||
|
|
"raw": "rest-facade@^1.10.0",
|
||
|
|
"scope": null,
|
||
|
|
"escapedName": "rest-facade",
|
||
|
|
"name": "rest-facade",
|
||
|
|
"rawSpec": "^1.10.0",
|
||
|
|
"spec": ">=1.10.0 <2.0.0",
|
||
|
|
"type": "range"
|
||
|
|
},
|
||
|
|
"_requiredBy": [
|
||
|
|
"/auth0"
|
||
|
|
],
|
||
|
|
"_resolved": "https://registry.npmjs.org/rest-facade/-/rest-facade-1.10.1.tgz",
|
||
|
|
"_shasum": "a9b030ff50df28c9ea1a2719f94e369c47167d20",
|
||
|
|
"_shrinkwrap": null,
|
||
|
|
"_spec": "rest-facade@^1.10.0",
|
||
|
|
"_where": "/home/jdaugherty/work/GT2/GT2-Android/node_modules/auth0",
|
||
|
|
"author": {
|
||
|
|
"name": "Nicolás Gonzálvez"
|
||
|
|
},
|
||
|
|
"bugs": {
|
||
|
|
"url": "https://github.com/ngonzalvez/rest-facade/issues"
|
||
|
|
},
|
||
|
|
"dependencies": {
|
||
|
|
"bluebird": "^2.10.2",
|
||
|
|
"change-case": "^2.3.0",
|
||
|
|
"deepmerge": "^1.5.1",
|
||
|
|
"superagent": "^3.8.0",
|
||
|
|
"superagent-proxy": "^1.0.2"
|
||
|
|
},
|
||
|
|
"description": "Simple abstraction for consuming REST API endpoints",
|
||
|
|
"devDependencies": {
|
||
|
|
"chai": "^3.4.0",
|
||
|
|
"coveralls": "^2.11.4",
|
||
|
|
"mocha": "^2.3.3",
|
||
|
|
"mocha-lcov-reporter": "^1.0.0",
|
||
|
|
"nock": "^2.15.0",
|
||
|
|
"sinon": "^1.17.2"
|
||
|
|
},
|
||
|
|
"directories": {
|
||
|
|
"doc": "docs",
|
||
|
|
"test": "tests"
|
||
|
|
},
|
||
|
|
"dist": {
|
||
|
|
"integrity": "sha512-MYHUAxNQYkD/ejvQX1CY8pvPseKX5G4dWDRNv1OFNBxn4b063rvDyqpWkjdtP8QouhtAcf91HIUrBdPq08puiA==",
|
||
|
|
"shasum": "a9b030ff50df28c9ea1a2719f94e369c47167d20",
|
||
|
|
"tarball": "https://registry.npmjs.org/rest-facade/-/rest-facade-1.10.1.tgz"
|
||
|
|
},
|
||
|
|
"gitHead": "d92ee3a2af9e128379e64ec60e3ea96c5c1a90da",
|
||
|
|
"homepage": "https://github.com/ngonzalvez/rest-facade#readme",
|
||
|
|
"keywords": [
|
||
|
|
"facade",
|
||
|
|
"rest",
|
||
|
|
"api"
|
||
|
|
],
|
||
|
|
"license": "MIT",
|
||
|
|
"main": "src/index.js",
|
||
|
|
"maintainers": [
|
||
|
|
{
|
||
|
|
"name": "ngonzalvez",
|
||
|
|
"email": "n.gonzalvez@outlook.com"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"name": "rest-facade",
|
||
|
|
"optionalDependencies": {},
|
||
|
|
"readme": "# rest-facade [](https://travis-ci.org/ngonzalvez/rest-facade)\n\nNode.js module that abstracts the process of consuming a REST endpoint.\n\n\n## Installation\n\n npm install rest-facade\n\n\n## Usage\n\n### Create a new endpoint client\n\nWhen creating a new client, a URL must be given as first arguments. If the URL have dynamic params, those variable params must be marked with the colon notation, as shown below.\n\n~~~js\nvar rest = require('rest-facade');\nvar options = {\n headers: {\n Authorization: 'Bearer token'\n },\n errorFormatter: {\n name: 'error.title',\n message: 'error.text',\n }\n};\n\nvar Users = new rest.Client('http://domain.com/users/:id', options);\n\n// The URL can have several dynamic params.\nvar UserVideos = new rest.Client('http://domain.com/users/:userId/videos/:slug');\n~~~\n\n\n### Get all instances from the API\nThe `getAll()` method can take an optional object as first parameters specifying the URL params. Considering the UserVideos model from last example:\n\n~~~js\n// Retrieve all videos from the user with ID 4.\n// This will resolve to a \"GET http://domain.com/users/4/videos\" request.\nUserVideos\n .getAll({ userId: 4 })\n .then(function (videos) {\n console.log(videos.length, 'videos retrieved');\n });\n~~~\n\n\n### Get one instance from the API.\n~~~js\n// Retrieve the user with ID 4.\nUsers\n .get({ id: 4 })\n .then(function (user) {\n console.log(user);\n });\n~~~\n\n\n### Create a new instance and save it to the API\nThe create method can be called using several signatures.\n\n- `create(data)` returns a Promise.\n- `create(urlParams, data)` returns a Promise.\n- `create(data, callback)` doesn't return a promise.\n- `create(urlParams, data, callback)` doesn't return a promise.\n\n~~~js\nUsers\n .create({ firstName: 'John', lastName: 'Doe' });\n .then(function (user) {\n console.log('User created');\n });\n\nUserVideos\n .create({ userId: 4 }, { title: 'Learning Javascript', slug: 'learn-javascript' })\n .then(function (video) {\n console.log('User video created');\n }):\n~~~\n\n\n### Delete an instance from the API by ID\nAs it was the case with the `create()` method, `delete()` can also be called with different signatures.\n\n- `delete(urlParams)` returns a Promise.\n- `delete(callback)` returns a Promise.\n- `delete(urlParams, callback)` doesn't return a Promise.\n\n~~~js\nUsers\n .delete({ id: userId })\n .then(function () {\n console.log('User deleted');\n });\n\n// This will resolve to: DELETE http://domain.com/users/videos/learn-javascript\nUserVideos\n .delete({ slug: 'learn-javascript' })\n .then(function () {\n // ...\n });\n~~~\n\n\n### Update an instance.\n\nThere are 2 ways to update data, if you are using correctly the HTTP methods, 1 is PUT and the other one is PATCH, rest-facade supports both of them:`Client.update` and `Client.patch`.\n\nAs with the previous methods, an object with the URL parameters must be provided as first argument. The second argument must be an object with the new data.\n\n#### PUT request\n~~~js\nUsers\n .update({ id: userId }, data)\n .then(function () {\n console.log('User updated');\n });\n~~~\n\nor\n\n~~~js\nUsers\n .put({ id: userId }, data)\n .then(function () {\n console.log('User updated');\n });\n~~~\n\n#### PATCH request\n\n~~~js\nUsers\n .patch({ id: userId }, data)\n .then(function () {\n console.log('User updated');\n });\n~~~\n\nBoth functions work exactly the same, the only difference is the method used to perform the request.\n\n### Plain HTTP requests\nIn case you don't want to use the all the fancy abstractions (`create`, `update`, `delete`, `getAll`) you can also send plain HTTP requests using the HTTP method function.\n\n\n~~~js\n// GET request.\nUsers.get(qsParams[, cb]);\n\n// POST request.\nUsers.post(qsParams, data[, cb]);\n\n// PUT request.\nUsers.put(qsParams, data[, cb]);\n\n// PATCH request.\nUsers.patch(qsParams, data[, cb]);\n\n// DELETE request.\nUsers.
|
||
|
|
"readmeFilename": "README.md",
|
||
|
|
"repository": {
|
||
|
|
"type": "git",
|
||
|
|
"url": "git+https://github.com/ngonzalvez/rest-facade.git"
|
||
|
|
},
|
||
|
|
"scripts": {
|
||
|
|
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec $(find ./tests -name *.tests.js) && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
|
||
|
|
"test": "mocha $(find ./tests -name *.tests.js) --opts mocha.opts",
|
||
|
|
"test-watch": "mocha $(find ./tests -name *.tests.js) --opts mocha.opts --watch"
|
||
|
|
},
|
||
|
|
"version": "1.10.1"
|
||
|
|
}
|