Comments (10)
Yep good call. I'm thinking two options:
- We default to all endpoints having a version (starting with 1), which you can overwrite
- We do as you suggest which would force people to always define custom service wrappers when they want to version things
There may be another way to have this configurable without forcing custom service wrappers. I'll have to look into this one.
from feathers.
I am not so sure if versioned URIs are really REST-ful (see http://stackoverflow.com/questions/972226/how-to-version-rest-uris). You should do versioning via custom content types (e.g. myapp/json+v1
) and content negotiation. For versioned URIs you can always do
app.use('/v1/todos', oldTodoService)
.use('/v2/todos', todoService)
It would be great to make the default REST provider more HTTP compliant and RESTful in this aspect though (e.g. by adding custom content types).
from feathers.
I don't thinking versioning really breaks REST but I get what @daffl is saying. Let's discuss this a bit.
from feathers.
A clean, easy and with backward compatibility solution will be just check if version is defined, if not just do as now.
With this solution you will not break existing projects, because if someone is using it in production will have troubles updating the lib.
And this is just a suggestion maybe some people like to naming their versions in other ways, but I found this one the most easy to understand, a good lecture of best practices are API FAÇADE PATTERN and
WEB API DESIGN
The main reason to versioning its to evolve your api without worrying to break your current production apps thats are consuming it....
from feathers.
I agree we do need to support versioning in some fashion but after thinking about it a bit more I'm inclined to go with what @daffl posted above. You can always do:
app.use('/v1/todos', oldTodoService)
.use('/v2/todos', todoService)
It's kind of crappy if you want to version all of your resources but it's not really any different than what you had suggested. It'll be much more apparent to someone else reading your code as to how the resources are versioned instead of having look for the version buried in the resource handler.
from feathers.
I don't think it would be even that crappy. This is where Uberproto can come in handy:
var TodoService = Proto.extend({
get: function(id, params, callback) {
callback(null, {
id: id,
description: 'You have to do ' + id
});
}
});
var NewTodoService = TodoService.extend({
get: function(id, params, callback) {
this._super(id, params, function(error, todo) {
todo.user = params.user;
callback(null, todo);
});
}
});
var app = feathers();
app.use('/v1/todos', TodoService.create())
.use('/v2/todos', NewTodoService.create());
This makes version specific URIs very easy and I don't think it needs to be an explicit feature.
I am still inclined improving the REST-fulness by doing things like versioning through custom media types but I'll add a separate issue for that.
from feathers.
Well, its your project then I will redirect the suggestion to, the middlewares works the same as express? can I write a middleware that do the versioning url?
As I see you just use
var TodoService = Proto.extend({
version: 1,
get: function(id, params, callback) {
callback(null, {
id: id,
description: 'You have to do ' + id
});
}
});
app.use(require('feather-version-middleware'));
app.use('/todos', TodoService.create());
// Then I get /v1/todos
Also talking about middleware It will be cool to have a router system
// controllers/v1/todo.js
module.exports = Proto.extend({
version: 1,
get: function(id, params, callback) {
callback(null, {
id: id,
description: 'You have to do ' + id
});
}
});
app.use(require('feather-routes-middleware'));
app.use('/todos', 'v1/todos');
// Then I get /v1/todos
I know is possible, just want to know how middleware works on feather, because I have an app with this structure in express and will be cool to migrate to feather, that something like this.
var express = require('express')
, app = express()
, port = process.env.PORT || 5000
, routes = require('express-path');
app.use(express.logger());
app.use(express.json());
app.use(express.urlencoded());
// Load routes
routes(app, [
['/status', 'api/status#index', 'all'],
// email
['/v1/email/send', 'api/v1/email#send', 'post'],
['/v1/email/subscribe', 'api/v1/email#subscribe', 'post'],
['/v1/email/unsubscribe', 'api/v1/email#unsubscribe', 'delete'],
]);
app.listen(port, function(){
console.log('Listening on port ' + port);
});
If says that I migrate to feather with the version middleware my routes will be just
routes(app, [
['/status', 'api/status'],
['/email', 'api/v1/email']
]);
This is the better way to don't mess with your goals and also have a very customisable module, so we don't need to hack the entire module to adapt to what we want.
Last question is, feather is just a CRUD or supports custom methods? just like my examples.
Regards
from feathers.
Technically what you want to do should work, you can definitely create your own middleware that does the version URIs for you. I haven't used express-routes but what basically happens when you do something like
app.use('/todos', {
todos: [],
// Return all todos from this service
find: function(params, callback) {
callback(null, this.todos);
},
// Create a new Todo with the given data
create: function(data, params, callback) {
data.id = this.todos.length;
this.todos.push(data);
callback(null, data);
}
});
is for the REST services it registers something similar to app.get('/todos', someWrapperForServiceGet)
and app.post('/todos', someWrapperForServiceCreate)
and you can just add your own before and after that. http://feathersjs.com/#toc8 talks a little bit more of how services relate to your middleware.
Again, versioning is definitely a valid concern and we'll keep it in mind for the future.
from feathers.
Thanks, now I will do some homework and see whats happen.. Regards
from feathers.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs.
from feathers.
Related Issues (20)
- Issue creating a new project after changing NPM's folder routes HOT 5
- is operator option deprecated really?
- "Creating an app" instructions fail without significant further undocumented action (Win11)
- "See API docs for all 180+ supported oAuth providers" is not clear enough
- feathers generate authentication fails on typescript projects (Win11) HOT 2
- Minor issue with authentication generator if service name is not "user"
- Schema resolving to unknown or any with queryProperty HOT 4
- $select should not be limited by query properties in _find
- AuthenticationService getPayload method should use payload of AuthenticationResult HOT 1
- Custom Service Routes beyond CRUD (without using X-Service-Method)
- virtual properties have inconsistent behavior with query
- How can I query postgres jsonb column with knex adapter? HOT 1
- Using API key authenticaion as per Feathers documentation causes TS compilation errors HOT 1
- [Feature Request] Add an option to use Jest instead of Mocha as the testing framework HOT 3
- Wrong value for context.method in create hook HOT 3
- Service adapter `operators` property marked as deprecated while still needed to use MongoDB specific operators starting with `$` HOT 1
- Re-initialize a service with children.
- Knex migration:make format not compatible with Feathers ES module settings HOT 1
- [Question] How to unit test when using @feathersjs/mongodb?
- @feathersjs/schema resolver throws unhelpful error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feathers.