5

Sometimes vaguely I hear that

Apache Sling more REST than Spring-mvc

from my colleagues.

I don't have possibilities to know about it from them. I have enough experience with Spring-mvc and I am novice in Apache Sling.

Can anyone explain the above quote?

P.S.

I want to see the list of non-REST features of these products.

for example: Spring-mvc allow to use session attributes and it is contradicts REST principe - to be stateless.

rakhi4110
  • 9,253
  • 2
  • 30
  • 49
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

3 Answers3

5

I agree with others that it's hard to measure the RESTfulness of a framework ;-)

And my knowledge Spring MVC is very limited, so I cannot comment on that.

Apache Sling fosters a RESTful way of designing applications, due to its core design and concepts like resources being first-class citizens, default 1:1 mapping of URLs to the content repository, etc.

If you follow its design patterns and examples you're very likely to end up with an application that's RESTful, with clean URLs, no HTTP sessions, HTTP methods which do the right thing etc.

You can also do non-RESTful things with Sling but it's harder, you'd be fighting against Sling natural way of doing things.

So Sling naturally leads you to RESTful applications. Other frameworks might allow you to be RESTful or not, with equal weight. In Sling the emphasis is clearly on being RESTful, and all the core tools and techniques help you get there.

Bertrand Delacretaz
  • 6,100
  • 19
  • 24
  • **You can also do non-RESTful things with Sling but it's harder** example please – gstackoverflow Mar 28 '14 at 10:34
  • 1
    Sling servlets for example can be mounted on specific paths instead of wired to resource types which is the default [1] and is usually more RESTful. Also, I don't think Sling prevents you from using HTTP sessions, but by default it doesn't use any so you don't get help from the framework for that. [1] as described at http://sling.apache.org/documentation/the-sling-engine/servlets.html – Bertrand Delacretaz Mar 28 '14 at 14:23
1

There's no such thing as a framework being more or less RESTful than the others. This is like saying the materials used to build a house make it more or less fitting to a particular architectural style. What will say if your application is more or less RESTful is how you design it, and how your clients access it. You can have a RESTful application using no framework at all, as long as it fills the REST constraints. And you can make an application that isn't RESTful at all if you disregard those.

What will dictate if your application is more or less REST than others isn't the framework you're using, it's:

  • Being stateless.
  • Being cacheable.
  • Clients don't require out-of-band information (HATEOAS).
  • Respecting the standards of the underlying protocol.
  • Respecting the client-server architecture.

Be aware that REST isn't an adequate solution to most problems people have. What most people call REST is simply any HTTP API that isn't SOAP, and your colleagues are probably just trying to appeal to REST as an authority in order to give weight to their personal preferences.

Pedro Werneck
  • 40,902
  • 7
  • 64
  • 85
  • you are right But!!! you can make your house using 1.flat straight wood and 2. curves of wood and then plug the hole. In both variants you will get house but first variant more corresponds for building. – gstackoverflow Mar 27 '14 at 18:41
  • 1
    That's the problem with analogies. If you take them too seriously, they hinder understanding instead of helping with it. REST is an architectural style. If you'll follow that style or not, it doesn't depend on the framework or the protocol you're using. You can make REST over FTP if you want. – Pedro Werneck Mar 27 '14 at 19:39
  • I'd say that frameworks can be more or less RESTfully-oriented, and I'm pretty sure that's precisely what's being addressed in the question. That said, I'm not convinced the question is on-topic on SO. – Dave Newton Mar 27 '14 at 21:58
  • Can one get HATEOAS formatted responses from sling? I haven't seen how it's possible to include child and parent references in sling json responses. – Bruce Edge Nov 12 '14 at 18:22
1

Apache Sling is specifically designed to facilitate applications that actually adhere to restful constraints - that is, that are designed to serve resources at URL locations without state change. Spring is more of a general purpose web application infrastructure.

Warren Dew
  • 8,790
  • 3
  • 30
  • 44
  • Maybe I am wrong But I think that method POST (for example) designed for creation and it changes server state. – gstackoverflow Mar 28 '14 at 06:04
  • @gstackoverflow state changing means changing state in a session bound to the user. REST backends should hold no state between requests (e.g. user is authenticated or not). Every request should supply all necessary information. – atamanroman Mar 28 '14 at 08:41
  • @Warren Dew. Is it possible to provide details as comparison of two frameworks? – gstackoverflow Mar 28 '14 at 11:30