danieltdt / node-json-rest-client Goto Github PK
View Code? Open in Web Editor NEWDefine REST client easily in nodejs
License: MIT License
Define REST client easily in nodejs
License: MIT License
Maybe this is just a documentation issue, but right now I have to add my 'base path' to each of my resource definitions:
var rest = require('json-rest-client')({
url: 'https://myapi.com/api/v1'
}, {
headers: {
'X-Client-Version': 'NodejsClient 0.0.1',
'Authorization': 'Bearer ' + config.token
}
});
return {
users: rest.resource('/api/v1/users') // Have to include path here otherwise it doesn't work
};
It would be nice to have just the path appended to the base path.
I was playing with the library the other day, and I may be mistaken but it would be nice to be able to optionally pass params to all()
and show()
to do things like pagination and search for example.
When using this library, I believe there is an issue with the performRequest
function just haven't had the time to diagnose why.
var assert = require('assert');
function ICMClient(config) {
assert(config, 'Config object must be present');
assert(config.token, 'Token must be present in config');
var rest = require('json-rest-client')({
url: config.url
}, {
headers: {
'X-Client-Version': 'NodejsClient 0.0.1',
'Authorization': 'Bearer ' + config.token
}
});
return {
users: rest.resource('/api/v1-DEV/users')
};
}
//url and token have been removed
var client = ICMClient({url: 'myapiurl', token: 'mytoken'});
var users = client.users().all();
module.exports = ICMClient;
Produces the following stacktrace:
/Users/vincent/WebstormProjects/icm-nodejs-client/node_modules/json-rest-client/node_modules/restify/lib/clients/json_client.js:84
callback((err || null), req2, res, obj);
^
TypeError: undefined is not a function
at parseResponse (/Users/vincent/WebstormProjects/icm-nodejs-client/node_modules/json-rest-client/node_modules/restify/lib/clients/json_client.js:84:9)
at IncomingMessage.done (/Users/vincent/WebstormProjects/icm-nodejs-client/node_modules/json-rest-client/node_modules/restify/lib/clients/string_client.js:151:17)
at IncomingMessage.g (events.js:180:16)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13)
It would be nice when doing rest.resource('/articles',...
to be able to specify which methods to exclude. The use case here is we have multiple resources in our API that you can create, but not update for example.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.