Delete multiple records using REST

Is a viable RESTful choice, but obviously has the limitations you have described. Don’t do this. It would be construed by intermediaries as meaning “DELETE the (single) resource at /records/1;2;3” — So a 2xx response to this may cause them to purge their cache of /records/1;2;3; not purge /records/1, /records/2 or /records/3; proxy a 410 response … Read more

API pagination best practices

I’m not completely sure how your data is handled, so this may or may not work, but have you considered paginating with a timestamp field? When you query /foos you get 100 results. Your API should then return something like this (assuming JSON, but if it needs XML the same principles can be followed): { … Read more

Why does int num = Integer.getInteger(“123”) throw NullPointerException?

The Big Picture There are two issues at play here: Integer getInteger(String) doesn’t do what you think it does It returns null in this case the assignment from Integer to int causes auto-unboxing Since the Integer is null, NullPointerException is thrown To parse (String) “123” to (int) 123, you can use e.g. int Integer.parseInt(String). References … Read more

Why does String.valueOf(null) throw a NullPointerException?

The issue is that String.valueOf method is overloaded: String.valueOf(Object) String.valueOf(char[]) Java Specification Language mandates that in these kind of cases, the most specific overload is chosen: JLS 15.12.2.5 Choosing the Most Specific Method If more than one member method is both accessible and applicable to a method invocation, it is necessary to choose one to … Read more

Why are Java Streams once-off?

I have some recollections from the early design of the Streams API that might shed some light on the design rationale. Back in 2012, we were adding lambdas to the language, and we wanted a collections-oriented or “bulk data” set of operations, programmed using lambdas, that would facilitate parallelism. The idea of lazily chaining operations … Read more

When do I use path params vs. query params in a RESTful API?

Best practice for RESTful API design is that path params are used to identify a specific resource or resources, while query parameters are used to sort/filter those resources. Here’s an example. Suppose you are implementing RESTful API endpoints for an entity called Car. You would structure your endpoints like this: GET /cars GET /cars/:id POST … Read more