-
Notifications
You must be signed in to change notification settings - Fork 29
hook on non-service apps? #39
Comments
Why would you not convert |
Yeah that could be. |
That's what I would recommend. It didn't take long for @daffl to convince me that you can pretty much map anything into services and REST methods, even if you need to spread it out across multiple services for the API to make sense. |
What if I want |
You could try using the feature that @daffl added yesterday where you can turn off the writing to the database on Or you could re-analyze if the desire for |
Yes. I need rethink my logic. I do not need tons of apps to connect with gateway. :) Thank you |
@wuyuanyi135 another option might be to create a app.use('/import/user', userImportService);
app.use('/import/data', dataImportService); I don't know what your imports do but you could write a generic import service that does whatever you need to do to import stuff. Writing custom services is actually pretty easy. They don't have to be database backed. They could talk to a file system, do stuff in memory or call remote APIs. You just implement specific service methods to automatically support the REST and socket transports. So if you did that you would just have: app.use('/import/user', importService);
app.use('/import/data', importService); |
I'd like to bring this back up, as I there are many cases where my application domain does not simply map to the current service model (which is very CRUD biased). A simple example is for a service that accepts multiple commands. E.g. I'm building a fancy multi-user chat app, and I want to accept the following commands:
Ideally I wouldn't want to describe each of these actions as nouns, but rather as verbs. As these methods are all related, I want them to exist in a single class, rather than create a new class for each action I want to support. To reiterate, although I could try to proliferate classes and try to map them to CRUD, it seems icky to me as it obscures the problem domain. Any help here on how to hook non-CRUD methods would be appreciated! |
I'm not going to be much help on hooking non rest methods, but when a use joins a chat room, what in your database changes? If you are storing the memberships directly in the chat room document then that maps to patching a chat room. If you are using an intermediary table to track which users belong in which chat rooms, then you are dealing with memberships, and not chat rooms, at that point. So it might be cleaner to create a memberships service for those methods. |
I agree with @marshallswain. With the right way of approaching the pattern I don't think there are really many cases where the service model couldn't be applied. I know it seems more intuitive to think in verbs but it's actually a little weird because the platform we are all building for (the web) is based on resources (nouns) and a number of well defined verbs just like services are (those restrictions on the service interface are intentional). In your examples I'm not seeing why it couldn't be done as a service:
For more complex interactions you can also create one-off services that do several things at once. For example, I often have a dashboard service that aggregates a bunch of data and sends it all at once or a service with just a |
Thank you @daffl and @marshallswain. Although I see @daffl's mapping could work, I still find it to be obscuring the application domain. In particular, if I'm inspecting the application logs after the fact, it's really hard to look at the logs and understand user intent (a lot of forensics to differentiate between all the overloaded patch operations!), and the names for what I'm actually intending to do get lost by forcing the domain to be mapped to a RESTful API. I think I'll try @daffl's suggestion on building a one-off service with just a And on a slightly unrelated note, when you perform a bunch of actions with the overloaded |
I want to authenticate the user before the request
app.post('/import', import)
which is not a feather service.
Is it possible to use the hook
instead of writing the middle-ware by myself?
The text was updated successfully, but these errors were encountered: