RESTful design: when to use sub-resources? [closed]

A year later, I ended with the following compromise (for database rows that contain a unique identifier): Assign all resources a canonical URI at the root (e.g. /companies/{id} and /employees/{id}). If a resource cannot exist without another, it should be represented as its sub-resource; however, treat the operation as a search engine query. Meaning, instead … 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

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

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)