Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you build a RESTful Business Logic Layer?

I've built a RESTful service for the Data Access Layer (DAL) of my architecture:

POST http://example.com/data/User
GET|PUT|DELETE http://example.com/data/User/{UserId}

However, for the Business Logic Layer (BLL), a second non-RESTful service is used:

POST http://example.com/accountapi/register
POST http://example.com/accountapi/login

This BLL service, instead of making calls to the DAL service, it talks directly to the database.

How would you improve this architecture?

  1. Should the BLL service call the DAL service ?
  2. Should I drop the DAL service and only expose the BLL service ?
  3. Should I, somehow, inject business logic on my RESTful DAL service ? If yes, how ?
like image 753
Max Toro Avatar asked Dec 20 '09 20:12

Max Toro


People also ask

What is business logic in REST API?

Business logic is what happens between the user interaction and internal data persistence. It determines what data is to be collected from the user, how it's stored, and where it goes. If APIs handle the what of your workflows, business logic handles the how.

Which architecture has business logic layer?

A multitier architecture formalizes this decoupling by creating a business logic layer which is separate from other tiers or layers, such as the data access layer or service layer.

Which layer of the application is used to implement the business logic?

The Business Logic Layer also known as BLL act as an intermediate between the Presentation Layer and the Data Access Layer (DAL). This layer handles the business logic, business rules as well as calculations.


1 Answers

To answer the main question. No, not really. To answer the secondary questions. None of the above.

REST based architectures do not fit nicely into the standard 3 tier model. The simplistic view of the three tiered model looks like this:

Presentation Layer <-> Business Logic Layer <-> Data Layer

Consider for a moment breaking the presentation layer into two parts,

Rendering Layer <-> User Interface Content <-> BLL <-> DAL

If you think about a regular Web application, the browser takes HTML, CSS and Javascript content and renders them visually in a browser. It is the User Interface Content layer that the REST constraints apply to. This is most obvious if you think about the hypermedia constraint. REST interfaces are mean to be navigated just like user interfaces are. REST interfaces return representations of resources.

REST interfaces should return user interface content that is independent of how the user interface will be displayed.

REST Client <-> REST Interface <-> BLL <-> DAL

In my opinion REST clients come in two forms, either very thin media type rendering engines (e.g. Web browsers) or screen scrapers (spiders, mashups). I use the term "screen scraper" loosely because if you choose your media-types wisely it should be trivial for the client to scrape the data out of your user interface content.

Any attempt to expose Business Logic Layers as REST interfaces usually has a few effects. Developers end up asking how to do transactions in REST. They end up creating huge amounts of coupling between the client and the BLL interface because of the need to expose semantically rich representations. They forget all about the hypermedia constraint, because much of that linking information is not available in the business logic layer. And they start to complain about the performance overhead of HTTP and text based content types.

like image 158
Darrel Miller Avatar answered Sep 28 '22 07:09

Darrel Miller