Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable API route #322

Closed
obrienmd opened this issue Apr 13, 2013 · 12 comments
Closed

Configurable API route #322

obrienmd opened this issue Apr 13, 2013 · 12 comments

Comments

@obrienmd
Copy link

Does it make sense to allow the API route to be configurable, so instead of '/tasks/create' you could prepend something, like '/api/tasks/create'?

@colinwren
Copy link
Member

Have you looked at the config/routes.js file?

I think adding this to that file will get you the result you want:

'post /api/tasks/create': {
    controller: 'tasks',
    action: 'create'
 }

@obrienmd
Copy link
Author

That's reasonable of course... But we lose the nice automagic REST stuff.

@mikermcneil
Copy link
Member

@obrienmd yeah :\ Got any ideas on how to resolve this? Maybe the following (assuming the entity is 'task', e.g. model is api/models/Task.js and controller is api/controllers/TaskController.js):

// in config/routes.js

`/api/tasks': {
  controller: 'task'
}

Right now, the example above would route /api/tasks to TaskController.index(), but maybe it makes sense to have it shift the entire blueprint?

@obrienmd
Copy link
Author

Right - Was hoping to shift the entire blueprint... Not sure about the balance of consistency (i.e. should socket.io calls also be re-routed?) vs complexity.

This is my first real day hacking on this, so I don't have any great ideas to submit. Just a through from reading the constant barrage of 'REST API design' blog posts over the last 6 months :)

@colinwren
Copy link
Member

I think this would be a nice solution for changing the rest endpoint:

'rest /api/tasks': {
    controller: 'task'
 }

It would just switch all the default routes from /tasks to /api/tasks

@obrienmd
Copy link
Author

I could get behind that.

@joafeldmann
Copy link

Also support for api versioning would be great. Something like:
/api/v1.0/tasks
/api/v1.5/tasks

@dasher
Copy link
Contributor

dasher commented Jun 13, 2013

While it's not bullet-proof - you can achieve that now @joafeldmann with:

"/api/v1.0/:action" : {
  controller: apicontrollerv1_0
},
"/api/v1.5/:action" : {
  controller: apicontrollerv1_5
}

@ghost
Copy link

ghost commented Jun 15, 2013

Can I suggest we do something like this

"/tasks" : {
    namespace: 'api/v1',
    controller: 'task'
}

I'm not [yet] familiar with the codebase, but adding something like namespace shouldn't break backward compatibility while adding a url prefix. The default setting in the code could be namespace: ''.

@mikermcneil
Copy link
Member

Check out the hooks branch and how this is implemented in the 'controllers' hook-- I haven't made it configurable for controller yet, and there I've got a 'prefix' config, so you can control all blueprints at once, but I rather like your approach here better for individual controllers!

Mike's phone

On Jun 15, 2013, at 14:25, Nico notifications@github.com wrote:

Can I suggest we do something like this

"/tasks" : {
namespace: 'api/v1',
controller: 'task'
}
I'm not [yet] familiar with the codebase, but adding something like namespace shouldn't break backward compatibility while adding a url prefix. The default setting in the code could be namespace: ''.


Reply to this email directly or view it on GitHub.

@Zolmeister
Copy link
Member

http://sailsjs.org/#!documentation/config.controllers
see prefix controller config

@mikermcneil
Copy link
Member

Just a heads up-- I'm planning on adding a per-controller override for the blueprint configs (prefix, expectIntegerId, shortcuts, rest, actions) in an upcoming patch release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants