Open gr0uch opened 11 years ago
Hi Dali,
Before I respond to each of your points individually, I think there is a misunderstanding about the relationship between routes and actions that needs to be cleared up.
Route objects and action objects should be named the same - that is how the action is chosen. Under the hood, Simple API loops through each of the routes - the first things it checks is if there is an action defined with the same name as the key of the route. Then it does the path matching and parameter pulling, and passes all that to the matched action.
Now specific responses:
after
hook, and then decided there was no need
because of the convenience response functions. Simple does not do any
fancy stuff after your controller actions are called, so any post
processing you want done can be easily manually defined or just overridden
in the response functions. That said, I'm not closed to the idea of an
after
hook - could you provide some use cases so that I can make sure I
architect it in the most useful way?Also, Fortune looks great! Seems like a more poweful version of Deployd.
I have an eventual feature planned to write common top level controller actions (PUT, POST, etc). That will require model integration, which is something I'm thinking very hard about before I actually build it. I want my models to be DB agnostic - I haven't found the right way to do that, though.
By the way, I'm going to do a more formal review of these items and then break them out into individual issues. That fits better with my ( and OS in general) development processes. I'll copy you on each of the issues so you get notified.
Thanks! On Sep 10, 2013 1:05 AM, "Dali Zheng" notifications@github.com wrote:
Hi, I'd like to address a few concerns about this package:
- The key names in the routes object seem redundant. This is mostly an aesthetic concern, but it does force the user to think of a name for a route, even if the route is self-descriptive.
- Not sure about the purpose of differentiating :, %, or * parameters, other than to have some sort of type casting. After all, the URL is just a string.
- Making the before method synchronous really limits what you can do with it. For example, what if I want to query the database to check if the currently authenticated user has permissions on a resource? Consider returning a promise or callback.
- Come to think of it, it might be missing an after method, which gets called after a resource is loaded, to transform the response.
- It's unclear how a route triggers an action. How does a route know what is the corresponding action?
- Is there any point to the helpers object, or is it there for organizational purposes?
P.S. I've authored a package that may be similarhttps://github.com/daliwali/fortune.
— Reply to this email directly or view it on GitHubhttps://github.com/josephwegner/simple-api/issues/8 .
Ah, your explanation of the routes clears things up.
Just an example of how an after
hook might be useful: setting the Content-Type
on every response, without having to define this on each controller, or formatting the output in a certain way (no spaces for production, 2 space indent for dev).
I want my models to be DB agnostic - I haven't found the right way to do that, though.
This is something I've done with Fortune: define models once, use any adapter. Models are wrapped in a resource object, and the wrapper contains common methods to act on a model (find, create, update, delete).
Hi, I'd like to address a few concerns about this package:
routes
object seem redundant. This is mostly an aesthetic concern, but it does force the user to think of a name for a route, even if the route is self-descriptive.:
,%
, or*
parameters, other than to have some sort of type casting. After all, the URL is just a string.before
method synchronous really limits what you can do with it. For example, what if I want to query the database to check if the currently authenticated user has permissions on a resource? Consider returning a promise or callback.after
method, which gets called after a resource is loaded, to transform the response.helpers
object, or is it there for organizational purposes?P.S. I've authored a package that may be similar.