I would have gladly just linked to somebody else’s sample clients, but I couldn’t find any remotely complete or professional-grade code (complete working program with error-handling, Basic auth and timeout.)
The closest to useful REST clients that I saw were the Java tutorials by mkyong.com, RESTful Java client with Apache HttpClient
Here’s my notes:
- tough to find the a working HTTP class for Java 1.8 on Centos7. I couldn’t get Apache HTTPClient imports working, so I ended up using HttpURLConnection
- first experience with immutable data collections – quite jarring to realize you have to copy anything returned from a library first to change it. And an int is not an Integer, and a String is not a StringBuffer. Hahaha, good one!
- somewhat of a learning curve for java build process. See make_java.sh for a minimal build tool
- I wouldn’t be surprised if Java’s legendary slowness and memory bloat are from the above issues, obvious even from a 200-line program.
- since Java uses block scope, when you add try/catch/finally blocks, variables referenced in catch/finally blocks must be moved outside the enclosing try scope. Makes code a lot messier. In Java 7, try-with-resource partially solves that.
- overall, programming in Go is a pretty nice experience. The included net/http package has everything you need.
- but “encoding/json” is overly-complicated. Some XML-head must have designed it.
- not sure why Go treats unused modules and variables as fatal compiler errors
- http.StatusNoContent appears to be missing from package net/http
- used the requests HTTP module
- felt comfortable until running Pylint and discovering how freaky the python community can get (scoring my working program -1.5/10, but getting 10/10 after whitespace-only changes. Really?)
- nice indenting:
pindent.py -r -s 4 -e
- used the
- elegant, beautiful OO code without even trying.
- got it working the fastest, but then took longer to polish it
- wish there was a lint for PHP
- not bad – straight-forward to do various requests and get responses
- inadequate for REST API programming, more for manually fetching files only
- LWP is mature, well-documented and readily available and made Perl the easiest scripting language to work with overall
- Perl’s built-in lint checking (strict and diagnostics) is much appreciated after its lack in PHP, Python and bash.
RESTful Java client with Apache HttpClient
Why Pylint is both useful and unusable, and how you can actually use it
Notes on Managing Java in the Cloud
Static typing will not save us from broken software
OpenFeign Java HTTP Client Library
Java: How To Read a Complete Text File into a String
Golang’s Real-time GC in Theory and Practice