简体   繁体   中英

REST - Application layer or Service layer?

I am writing web application which exposes REST interface and web socket for clients. This project interacts with underlying database. The UI layer and overall business logic is handled as separate project. Now I wanted to apply layers in this web application.

I have split my web application as,

 1. Service layer (Exposes REST and Websocket) 2. Domain layer (Handling web application's Business logic) 3. Persistance layer (DB access) 

Is this separation right? or Should i consider REST as application layer ? Is application layer aka service layer ? Which is more meaningful here?

The REST interface belongs in the same layer as the UI. It is a way of interacting with your app, just doesn't have a user interface. I like to put the API in a separate project from the UI so it can be deployed separately and scaled separately. Ideally the UI would use the API for its data access.

With that said, asking this question implies you are designing your own architecture pattern, which is not a good idea. Much bigger brains that mine have attacked and solved this problems many times so you should pick one and use it. The one I find most flexible is the Onion Architecture ( https://dzone.com/articles/onion-architecture-is-interesting ), which fits well with DDD or Active Record. In the Onion Architecture, though, things are split between interface and implementation in a way that takes some getting used to so if you decide to migrate that way give yourself a little extra time to get accustomed to it. Once you do, you will be happy with the flexibility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM