-
Notifications
You must be signed in to change notification settings - Fork 221
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
Best practices and abstractions #263
Comments
I'll defer to @vkostyukov and others, of course, but my own feeling is that providing higher-level abstractions like this in a Finch subproject would be reasonable—keeping it in this repository would make it easier to stay synced with core, and it would be pretty trivial to move it to a new If you're interested in writing a blog post about this work for the Finagle blog, @imliar, let me know—we'd love to have it. |
Thanks @imliar! This is a very very good question. And I believe everybody who is using Finch nowadays faced the same question. We've discussed this at lot, and I remember your participation in early discussions. Here is the short story. The was a ticket #204 "Finch in Action" about the same question - how to write services (organize your code) with Finch. We tried to come up with something that answers this question and the I personally believe that Future Finch with coproduct routers (see #221) merged with request readers into something like // helper/private routines are still endpoints so we can compose everything
val authrorize: Endpoint[AuthUser] = ???
val dumpToLog: Endpoint[Unit] = ??? // side effects
// will be exposed
val getUser: Endpoint[User] = authorize :: dumpToLog :: ....
val postTicket: Endpoint[Ticket] = authorize :: ....
Httpx.serve("8081", getUser :+: postTicket) That's being said, I hope we can go in that direction and be microservices-oriented thereby merging two layers (services and controllers) into a single layer of microservices that implement "open-closed" principle: open for reuse but closed for modification. With such toolchain, one can build a system that follow any possible style (i.e., CRUD). And my personal understanding that Finch should stay in library-scope so its users may be innovative in the approaches they use to organize a code around services. But this doesn't mean that everybody should invent his/her own style (backed micro-library) to work with Finch. We will provide a basic schema based on endpoints (see example above) so one can start with it and then wrap them with any number of abstractions (like controllers) he/her feel comfortable with. Quick example. Here is how the first ever Finch 0.1.0 code looked like. I also asked this question to myself 1 year ago and come up with that silly idea of extendable and composable services. And it worked great for me. As for today, I would probably stay within endpoints mentioned earlier. The bottom line is I'm doubtful about having this approach merged in Finch. But it might be a good idea to have it as a separate project or at least post a blog about it: this is very very valuable experience that worth sharing with the community. @imliar can we make a deal? Let's wait until endpoints are shipped (0.8 - 0.9) so you can play with them. I'm quite sure you will be happy to replace two layers of services and controllers with just a single layer or reusable endpoints. If it won't work for you, we will think about CRUD-style extension for Finch exposed as sub-project (maybe Although, it's not my jurisdiction to stop you from shipping this as a separate project in the Finagle organization. So you can totally work with @travisbrown on this direction. |
Okay, guys, I hear you. Let's wait until 0.7 release and I'll write smthing about actual version of finch. |
I have an update on this. |
@vkostyukov OH NOES, 404. |
@imliar link: https://gist.github.com/vkostyukov/411a9184f44a136e2ad9 @vkostyukov I like the idea of having micro-frameworks built on top of Finch for those that want them. My primary concern is this line from your write-up: |
I was tying to summarize my thoughts on this in Finch's best practices (see Big Picture). TL;DR I wish we could keep Finch in its current state (what I call "vanilla Finch") and not layer anything on top it. Although, because of its pretty generic abstractions, it should be possible to build any kind of face (i.e., CRUD) on top of Finch. That said, @imliar do you think we can close this ticket for now and for example, publish some Finch docs (under this repo) or even a complete example on CRUD approach? |
@vkostyukov Yea, I believe we can close it. |
Thanks @imliar! Feel free to open a PR within a simplified version of CRUD-style controllers - I think it would be super helpful for newcomers. Also, having this example live in the same repo as finch-core will ensure that it's always aligned with the latest API. |
When we've started to use finch (from v0.5) as a basis for our REST/HTTP API we've struggled with a lack of some practices, guidelines and how-to about abstractions on top of underlying
Service[HttpRequest, HttpResponse]
.Finch by itself is a pretty low level layer which responds to work with HTTP requests/responses with some neat monadic extensions/ways to do. And nothing more. Finatra, for example, was built around
Filter/Controller
and its composition.So we decided to abstract it on our own.
Now our simple CRUD controller looks like that:
Looks pretty intuitive and simple as for me.
You may ask why do we ever need a controller layer when it's just a kind of proxy to services?
Well, it's a good place to do lazy authentication, check user permissions, validate input and many other things which are not welcome in a real business logic.
Yet it provides a simple way to compose all controllers together and bind it to HTTP port.
So here is a question.
Do we ever need this bicycle-boilerplate as a part of some finch ecosystem, some simple example & bootstrap for newbies?
I completely understand that this abstraction level should not be a part of finch core just because of its nature. I just wanna know if someone interested in that experience and how should I present it in that case - some article or even
finch-subproject
.The text was updated successfully, but these errors were encountered: