Hi there,

Just to chip in for balance.

We're using akka http and the DSL in a real world business app.

The fact we don't have hundreds of routes or don't have to call 10s of actors per request doesn't make our app any less a "real world business app".

Just that ours is small. And we're creating more apps this way and they too will be fairly small (call them microservices if you must) and we're happy to use the DSL.

Choice of solution is always context-dependent, so in the context of a big and complicated service perhaps the low-level api can be a better fit.

Not a reason to call the DSL an anti-pattern though, IMO.



Cheers,

Michal


On 19/04/17 04:57, Konrad Malawski wrote:
For starters: It's fine if your preference is to not use the DSL, no one will force you to; and that's also the reason the DSL is a separate artifact.

Also, your route here is definitely multiple things and those should be split up. Why make one huge route, make many vals with the small pieces (e.g. all the path prefixed parts in a real app would be in different traits in single vars) and then simply combine them.

If your specific complaint is about the missing ~, that's solved in two ways:
*1) just don't use ~. Use concat :-)*

concat(
   get {
     complete("ok")
   },
   path("hello") {
     complete("ok")
   }
)

2) JetBrains is actively working on adding Akka support, all across the board, including routes and other things in plain actors etc. One of the issues I opened and is being worked on right now is the ~ problem: https://youtrack.jetbrains.com/issue/SCL-11632 <https://youtrack.jetbrains.com/issue/SCL-11632#tab=History>

--
Konrad `ktoso` Malawski
Akka <http://akka.io> @ Lightbend <http://lightbend.com>

On 19 April 2017 at 12:48:21, kraythe (kray...@gmail.com <mailto:kray...@gmail.com>) wrote:

Sorry, I have been buried with work.

The problem with the DSL approach in my opinion is that it leaves too much space for error and strange things happening and at the same time it hamstrings you into a particular flow that may or may not be appropriate to the problem. Just to have some fun, this route doesn't work. It compiles just fine, the server comes up but nothing happens. Spot the problem?

|valroute ={path("orders"){authenticateBasic(realm ="admin area",myAuthenticator){user =>get {encodeResponseWith(Deflate){complete {// marshal custom object with in-scope marshallerretrieveOrdersFromDB }}}~post {// decompress gzipped or deflated requests if requireddecodeRequest {// unmarshal with in-scope unmarshallerentity(as[Order]){order =>complete {// ... write order to DB"Order received"}}}}}}~// extract URI path element as IntpathPrefix("order"/IntNumber){orderId =>pathEnd {(put |parameter('method!"put")){// form extraction from multipart or www-url-encoded formsformFields(('email,'total.as[Money])).as(Order){order =>complete {// complete with serialized Future result(myDbActor ?Update(order)).mapTo[TransactionResult]}}}~get {// debugging helperlogRequest("GET-ORDER"){// use in-scope marshaller to create completer functioncompleteWith(instanceOf[Order]){completer =>// customprocessOrderRequest(orderId,completer)}}}}path("items"){get {// parameters to case class extractionparameters(('size.as[Int],'color?,'dangerous?"no")).as(OrderItem){orderItem =>// ... route using case class instance created from// required and optional query parameterscomplete("")// hide}}}}~pathPrefix("documentation"){// optionally compresses the response with Gzip or Deflate// if the client accepts compressed responsesencodeResponse {// serve up static content from a JAR resourcegetFromResourceDirectory("docs")}}~path("oldApi"/Remaining){pathRest =>redirect("http://oldapi.example.com/"+pathRest,MovedPermanently)}}|

If you got that there is one missing ~ between the routes you have a sharp eye but the DSL wont tell you, the code compiles just fine. But there I thought the DSL was supposed to make everything easy. Nope, if you put directives in the wrong order, nest them in the wrong order, or anything like that the code doesnt warn you, it just refuses to run. Yes, you can scream "unit test everything" but really? Is this untyped Ruby here? Testing everything is not a strategy that scales well in business or endures in a long running codebase, its an academic construct that eventually crumbles under the real world.

The other problem with the routing is that it ties you into a certain set of directives and techs and breaking out of that is painful. Lets say you like the validation checking of Play-json over Spray-json? Can it be integrated with the route? With difficulty maybe but then you dont get the ability to handle errors like you do with the low level API. If the body doesnt parse out to the type the route blows up and the user gets back an internal error. What if I dont want to tell my users how to hack json to feed to my site? What if I dont want actors blowing up on internal errors? If so then I am up a creek of thin ice.

Subsequent to my OP, I sat down and worked with the DSL for a good week, integrating it into the business project I am working on. It was painful. Missing tilde causes routes to not work, wrong nesting, wrong order of directives, not able to validate my json and return better error structures or handle things conditionally. It turned into a royal nightmare and it was entirely unnecessary. I switched back to using the low level api and other than some annoyances with handling headers that could be nicer, it just worked. I have flexibility to return what I want, when I want. I can offload to an actor that calls 10 other actors and integrates the results of the other actors into one actor and so on. In short, yes it was a bit more verbose but it was clear, easier to understand, easier to maintain, static type checked and solid.

My personal conclusion is that the DSL is fine for simple projects but once you get into a real world business app, it starts to get in the way and frustrate.

-- Robert
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com <mailto:akka-user+unsubscr...@googlegroups.com>. To post to this group, send email to akka-user@googlegroups.com <mailto:akka-user@googlegroups.com>.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com <mailto:akka-user+unsubscr...@googlegroups.com>. To post to this group, send email to akka-user@googlegroups.com <mailto:akka-user@googlegroups.com>.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

--
Signature
<http://www.openbet.com/>         Michal Borowiecki
Senior Software Engineer L4
        T:      +44 208 742 1600

        
        +44 203 249 8448

        
        
        E:      michal.borowie...@openbet.com
        W:      www.openbet.com <http://www.openbet.com/>

        
        OpenBet Ltd

        Chiswick Park Building 9

        566 Chiswick High Rd

        London

        W4 5XT

        UK

        
<https://www.openbet.com/email_promo>

This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@openbet.com <mailto:postmas...@openbet.com> and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by OpenBet for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. OpenBet Ltd. Registered Office: Chiswick Park Building 9, 566 Chiswick High Road, London, W4 5XT, United Kingdom. A company registered in England and Wales. Registered no. 3134634. VAT no. GB927523612

--
     Read the docs: http://akka.io/docs/
     Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
     Search the archives: https://groups.google.com/group/akka-user
--- You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to