6 ms·
So what do people use as a server these days? All I want is to annotate some function calls with paths and have something handle http requests and mangle the i
by jtolmar 10y ago
So what do people use as a server these days?
All I want is to annotate some function calls with paths and have something handle http requests and mangle the input and output into json for me. Preferably in a boring safe language. Preferably in Java, the boringest safest language.
If I have to call a method on a provided object instead of returning in the name of async, great, that's fine too.
- moonshinefe 10y agoif it's not performance critical, I'd go with Python. If you need max performance, I guess Java or Go or something along those lines, though caching and other techniques can soften the blow of using a slower language quite a bit.
- robin_reala 10y agoSounds like a job for Dropwizard. http://www.dropwizard.io/ http://www.dropwizard.io/
- angryasian 10y agoTake a look at spring boot - http://projects.spring.io/spring-boot/ http://projects.spring.io/spring-boot/ its incredibly easy these days to do what you're suggesting in Java
- EtienneK 10y agoI second this. Spring Boot is the greatest thing to happen to Java in a long time... Well, that and lambdas...
- ganeshkrishnan 10y agoAnd if you want to add icing to the cake I suggest Jhipster. It has made my life considerably easy with it's angular JS support and spring boot /JSON/ API support. I could create an e-commerce website http://www.haggell.com http://www.haggell.com in a space of month using jhipster & angular.
- regularfry 10y agoTo echo the sibling comments, use what's in Go's stdlib and you get trivial build and deployment. Spring Boot, Dropwizard have a steeper on-ramp if you're not up on modern Java dev, and the deployment is fractionally more involved, but they're both good options.
- akerro 10y agoSpring Boot, Dropwizard, ASP, RoR
- lmm 10y agoI use Scala with spray.io. Plain-old-code rather than annotations or config files (they've structured their API so that you can write a route definition that looks almost like a config file - see e.g. https://github.com/spray/spray/blob/release/1.3/examples/spray-routing/simple-routing-app/src/main/scala/spray/examples/Main.scala https://github.com/spray/spray/blob/release/1.3/examples/spr... - but it's all plain old code that you can refactor according to the normal rules of refactoring code). You can use callbacks if you really want but generally you just return Futures and compose them with for/yield, which is the sweet spot IMO: your code can look like: for { user <- loadUser(userId) bestFriendId = user.friendships.maxBy(_.strength).friendId bestFriend <- loadUser(friendId) response = buildResponse(user, bestFriend) } yield response so there's very little overhead to doing async calls (just the difference between "<-" and "="), but you do have visibility over which calls are async and which aren't when you're reading the code. (async/await are arguably even better in this specific case, but they're tied to async, whereas for/yield is generic functionality that you can also use to e.g. manage database transactions). JSON-wise if you use spray-json-shapeless you get automatically derived json formats at compile time, so better performance than reflection-based approaches, O(1) code to support all your different data types, but if you accidentally try to include something that doesn't make sense to serialize (e.g. a file handle) then you'll get an error at compile time. Similarly, the output "adapter" is resolved implicitly at compile time, so once you've imported the adapter for spray-json and the spray-json-shapeless stuff you can do "complete(foo)" where foo is a Future[MyCaseClass] and it will work correctly, but if you try to complete with something that can't be converted to a valid HTTP response then you get the error at compile time. (And if you're already using Java, it runs on the JVM, with seamless interop with Java libraries; you can run it as a servlet too, so you can migrate a web API one endpoint at a time (using servlet routing) if you like).
- jtolmar 10y agoThis looks surprisingly close to the hypothetical dream framework in my head. I'll definitely take a look into it. I love the for/yield construct for handling boring concurrency.
- sotojuan 10y agoIf you're going to take the bait of this article, you can't use Java either [1] [1] http://harmful.cat-v.org/software/java http://harmful.cat-v.org/software/java
- douche 10y agoI think .Net Core is the new hotness, but I've enjoyed using the self-hosted Katana OWIN webserver components for the last couple of years. Slap something like WebAPI or Nancy on top of that, and it's really easy. Of course, Windows-only...