I'm trying to get more acquainted with rest and try to understand what layered system means in REST architecture. As far as i understand it means that if API has database it should be on different machine on different server and api call it when it is needed. The same with bussines logic, if call should be passed through some logic call is transfered to some other server and executed there. This also will help to solve performance issue if it exist. Am I right? please give any additional info
1 Answers
Well, I wouldn't think of a layered system as "each layer has to reside in a separate server'. It is more about the separation of concerns, i.e. every layer should have a single high-level purpose and deal only with that. I will try to explain better with an example of what is wrong :
@GET
public String myService() {
return "<html><body><div>HELLO</div></body></html>";
}
Here you have the service and presentation layer all mixed up. Instead, the service should just return "HELLO", while the client (which I assume here is a presentation layer) should be able to decide how to present the data. One of the most common architectures is the so-called 3-tier architecture, where you have data access, business logic and presentation. Services could be added as a separate layer, most commonly between business logic and presentation (so that you can apply the same business logic to different clients, e.g. web and mobile).

- 2,004
- 20
- 24
-
So what I understand from ur example, layered system should be something like this: `@GET public String myService(String mimeTipe) { return someClass.someMethod(mimeTipe); }` So will call method and give him parameter and we have no hardcoded pages inside our method, right? – Shell Scott May 18 '15 at 12:33
-
yes, exactly. The service's client can then decide what's the best way to present the data, which is something that the service hardly knows about (e.g. client is javascript running in a desktop/mobile browser). – francesco foresti May 18 '15 at 12:38