feathersjs / feathers Goto Github PK
View Code? Open in Web Editor NEWThe API and real-time application framework
Home Page: https://feathersjs.com
License: MIT License
The API and real-time application framework
Home Page: https://feathersjs.com
License: MIT License
It should not create a server but instead listening an existing server (http, https, express, etc).
Although fixed with #52, I think in 1.0 the REST provider shouldn't be added by default and just configured manually like everything else.
Also a must have feature, if you want to share your api to other developers
var todos = {
version: 1,
find: {
doc : {
description: 'Return a todo list',
// The params that the method receive
params: [ {
name: 'limit',
description: 'determine the number of items to return',
type: 'numeric',
required: false
} ],
// An output example
output: [{
name: 'Todo name',
status: 'finished'
}]
}
method: function(params...){...}
}
}
feathers().configure('documentation', true)....
Then you can call it just like GET /v1/docs/todos
if documentation is set to false it the docs path will not be initialised
It was inspired on Action Hero api documentation method
some thing like that:
socket.on('my/todos updated', { ids:[1,2,3], maxLenght: 200 }, function(todo) {
console.log('Got an updated Todo!', todo);
});
Brought up in canjs/canjs-feathers#2 for REST calls the user can only directly modify params.query
. Maybe, in order to be consistent, SocketIO and Primus calls should do the same thing and map params from the client into params.query
instead of passing them directly. That way it would be consistent and other params
properties can only be set on the server.
By default all services will be extended with Uberproto in https://github.com/feathersjs/feathers/blob/master/lib/application.js#L22. While this most likely works it isn't necessary if the object is already an instanceof Proto
.
This seems like a reasonable API format to support. What do you think?
I think it's a good idea to remove the x-powered-by header by default. Typical users do not need to know what server technology we are using. Plus, it gives hackers a basic set of attack vectors that will and won't work.
Does anybody have any objections to disabling the x-powered-by header by default?
Hi can i have both modes turned on at the same time in my application, some client side apps will use REST while the others (like my admin backend for real time service response) will use the socket.io module
It would be nice to have a way to send custom events to websocket clients. Is there an easy way to tap into the event system for that?
It would be nice to see how do you propose to implement authentication/session services with feathers. Esp. how to treat such actions as user activation, login with external accounts in standard manner.
In lib > application.js
inside the use()
function we need to take all arguments and then take the the first one as the path, and the last one as the service. The rest are middleware that should be proxied to express in the order that they come in.
hi,
how does one send an HTTP status code other than 200, either on success or on error? i'm trying to follow HTTP API best practices, something similar to this.
cheers!
Maybe we can do this via .configure(ssl)
which handle the ssl keys and overwrites our app.listen
call.
Hi, I'm in the process of creating an API using feathers. So far, it looks really promising!
One thing I haven't quite figured out is how to return custom error responses, especially ones that are well-formed JSON.
I got the following:
get: function(id, params, callback) {
callback({
status: 404,
message: {info: 'Not found.'}
});
},
I see that supplying an object with a status
key allows me to set the HTTP status. (Is this documented somewhere?)
The response body is [object Object]
though.
Even though the setup
method isn't called, the services work properly.
// app.js
require('feathers')()
.configure(function () {
var app = this;
app.use('/setup', {
get : function (id, params, callback) {
callback(null, {});
},
setup : function (app) {
console.log('setup');
}
});
setTimeout(function () {
app.use('/nosetup', {
get : function (id, params, callback) {
callback(null, {});
},
setup : function (app) {
console.log('no setup :(');
}
});
}, 100);
})
.listen(8080);
$ node app.js
setup
The REST provider shouldn't have a hard dependency on the bodyParser middleware. Users should set this up themselves.
For the 1.0 release we should update the way we generate the http://feathersjs.com website. Currently we are using a custom Grunt task that grabs the readme.md
from master and renders it into the template.
This works pretty well but it would be really nice to implement a simple static site generator Metalsmith that does the same thing but also adds a section for Feathers plugins (maybe there is a way to grab them directly from NPM) and articles. Articles can be how-tos and just submitted into the docs folder in the main repository. This hopefully makes it easy to contribute new ones.
Considering the following service:
var Service = {
find : function (params, callback) {
// ...
console.log(params);
}
};
When called via the REST API the console output is:
GET /users
{ query : {} }
But if you call the same method through a socket connection:
primus.send('users::find', {}, function () {})
{}
In my opinion it should either be {}
or { query : {} }
in both cases to be consistent, while I think {}
would make the most sense.
SocketIO 1.0 got released. We should migrate the provider and the examples for the 1.0 release.
I don't think we are actually handling websockets across multiple instances. We should look at the socket.io docs.
Support for Cluster to create a multi-core Node.js server.
This could be a plugin for Feathers, or a built-in feature as is Socket.io and Primus.
Source http://adamnengland.wordpress.com/2013/01/30/node-js-cluster-with-socket-io-and-express-3/
cluster = require("cluster")
http = require("http")
numCPUs = require("os").cpus().length
RedisStore = require("socket.io/lib/stores/redis")
redis = require("socket.io/node_modules/redis")
pub = redis.createClient()
sub = redis.createClient()
client = redis.createClient()
if cluster.isMaster
i = 0
while i < numCPUs cluster.fork() i++ cluster.on 'fork', (worker) ->
console.log 'forked worker ' + worker.process.pid
cluster.on "listening", (worker, address) ->
console.log "worker " + worker.process.pid + " is now connected to " + address.address + ":" + address.port
cluster.on "exit", (worker, code, signal) ->
console.log "worker " + worker.process.pid + " died"
else
app = require("express")()
server = require("http").createServer(app)
io = require("socket.io").listen(server)
io.set "store", new RedisStore(
redisPub: pub
redisSub: sub
redisClient: client
)
server.listen 8000
app.get "/", (req, res) ->
res.sendfile(__dirname + '/index.html');
io.sockets.on "connection", (socket) ->
console.log 'socket call handled by worker with pid ' + process.pid
socket.emit "news",
hello: "world"
I am trying to expose the services the same way as the providers. It doesn't work because when we are instantiating a service we are calling the "create" function which we have overridden. Refer to https://github.com/ekryski/feathry/commit/8b37fdc14b047e1a9aebdbba97adafad76a62c65#L1L13
At least want this for running tests.
Express accepts functions and/or express apps as middleware.
var app = require('express')();
app.use(function(){
});
app.use('/path', require('./otherapp'));
It's really useful to split an express app into smaller modules with single responsibilities. Feathers doesn't support it.
Request without Content-Type application/json have empty body.
I am using Postman REST Client and neglected to set the Content-Type
to application/json
which resulted in the body not being parsed by express.json
and it was passing data = {}
into my services' create
handler.
I suggest that, since JSON is the notation being used for serialization with Feathers, that if the Content-Type
is blank, it should default to application/json
.
there is an .idea dir in node package.
IMO is a must have feature, till now I can make by hand but will be nice if we can add just to the feather object version.
var todos = {
version: 1,
find: function() {...}
}
And when consume the api just you will call GET /v1/todos/
We should investigate if the SocketIO default configuration for transports should be changed to websockets first (or what other options make sense for production settings).
io.set('transports', [
'xhr-polling', 'websocket', 'flashsocket',
'htmlfile', 'jsonp-polling'
]);
than i create "Services" and use socket client it send 2 arguments to "get" method of Service but than i use REST api it call with 3 arguments?
what i do wrong ?
Hi,
i want to create a service with preconditions for the HTTP verbs POST, PUT, DEL. Only registered users should be allowed to POST new entries and only the creator should be able to PUT or DEL them. Express have a mechanism to assign multiple callbacks for an verb method . How can i do that for a service in feathers? I'm working on a feathers implementation for the MEAN-Stack.
Turn the server into an event emitter.
feathry.service('/api/users'/, {});
// -> '/api/users created'
// -> '/api/users updated'
// -> '/api/users destroyed
socket.emit('/api/users::create', {}, function(error, data) {});
Has anyone asked for Typescript definitions or tried using feathers with Typescript? I'm tempted to make them but unsure if they're actually wanted.
I was playing around with the todo example and I found a little bug. When I try to access this url: /todos/0
I get an error message saying Todo not found
. (And I know there is a todo with id 0).
I discovered that the TodoStore.Get()
method receives the id as a string then passes it along to the TodoStore.getById()
method which compares the passed in id to the ids in the todos list using the ===
operator. Since the ids stored in the todos list are numbers and do not match the type of the passed in string, the comparison fails.
The get method is never used in the todos example, so it probably never showed up.
Some possible solutions are to convert the string to a number before passing it to getById
or use the ==
operator so that it will not check type as well.
When Express 4.0 is officially out we should update as well. Might be a good time for a 1.0 release.
https://github.com/primus/primus
would allow for #20 and more.
I showed Feathers to my friends who are developing an app for a competition.
They are using MongoDB. I recommended Mongoose, since they are new to Node.js and such tools.
To get them started off I created a Mongoose Service that could be easily reused.
See example: https://github.com/DylanYoung/CoLab/blob/glavin/services/users.js
I plan on creating feathers-mongoose-service as a NPM package soon and publishing it. Just wanted to see if there is any interest ๐
Proposed usage:
var mongooseService = require("feathers-mongoose-service");
app.use("/users", new mongooseService(connection, { mongoose schema });
Update
I will be using this repo here: https://github.com/Glavin001/feathers-mongoose-service
Hi,
I implemented the REST authentication mentioned in #43 .
Now I want the same for the Socket.IO communication.
A user can use the find and get service but for create, update and delete he has to be logged in. Is there a way with feathersjs to implement that?
I can imagine the desire for something supports the feathers service api but with Koa. Do you guys have thoughts on this?
If a service returns a Promises/A+ Promise and the callback isn't called, the promise should be used to resolve the request.
var todoService = {
todos: [],
// Return all todos from this service
find: function(params) {
return Q(this.todos);
}
}
I should be able to hit a route like GET /users/:id/posts
and get all the users posts.
See https://github.com/feathersjs/feathers/blob/master/lib/providers/socketio.js#L29
Currently when there is an event it's broadcasted to all connected sockets. However, I would lie to utilize Socketio rooms to improve performance such that the client can subscribe and unsubscribe to rooms that are watch particular services or even updates to particular nodes with a given id.
I may in some cases want to join the room watching for changes to only the TODO service but not Users service (too many users? Or UI does not depend on such info).
Furthermore, I may want to watch for updates to a particular id of a given service.
I wanted to check for interest for making this a built in standard feature of feathers, or I will make a separate Socketio provider plugin.
It would be nice to have a SockJS-based provider available. It's kinda like socket.io but more websocket-y.
The Feathers server should directly extend from Express to avoid passing it around and having to call things like this.config.app
all the time. We are very likely to never use Feathers without HTTP anyway.
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.