REST API Client Computer Languages and Frameworks Survey


I recently wrote REST API client programs in several programming languages as a subproject of my Perl REST API Framework, and had some surprises, both good and bad.

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:

Java

  • 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
  • lint: javac -Xlint:all
  • 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.

Go

  • 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

Python

  • 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

Ruby

  • used the httparty HTTP framework
  • elegant, beautiful OO code without even trying.

PHP

  • got it working the fastest, but then took longer to polish it
  • wish there was a lint for PHP

curl

  • not bad – straight-forward to do various requests and get responses

wget

  • inadequate for REST API programming, more for manually fetching files only

Perl

  • 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

This entry was posted in API Programming, Java, Linux, Microservices, Open Source, REST API Programming, Tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.