Posts

Showing posts from August, 2018

Is it RESTful, or simply RPC?

"Pretty URLs like /employees/3 aren’t REST. Merely using GET, POST, etc. aren’t REST. Having all the CRUD operations laid out aren’t REST. In fact, what we have built so far is better described as RPC (Remote Procedure Call)... What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint? In other words, if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period. Is there some broken manual somewhere that needs to be fixed? of NOT including hypermedia in our representations is that clients MUST hard code URIs to navigate the API. This leads to the same brittle nature that predated the rise of e-commerce on the web. It’s a signal that our JSON output needs a little help. Introducing Spring HATEOAS (Hypermedia as the Engine of Application State), a Spring project aimed at helping you write hypermedia-driven outputs." Read here: https

Organize logs using MDC

MDC (Mapped Diagnostic Context) is supported by log4j, log4j2, and SL4J/logback and offers a key/value possibility to enrich log statements: public class MDC { //Put a context value as identified by key //into the current thread's context map. public static void put ( String key , String val ); //Get the context identified by the key parameter. public static String get ( String key ); //Remove the context identified by the key parameter. public static void remove ( String key ); //Clear all entries in the MDC. public static void clear (); } Add an aspect (filter/interceptor etc.) to pre-handle your requests and add the desired information: MDC . put ( "userId" , userId); MDC. put ( "correlcationId" , correlationId); In the log appender, the values can be retrieved using %X{<key>} log4j.appender.rollingFile.layout.ConversionPattern=[%d

REST - Richardson Maturity Model

"A model (developed by Leonard Richardson) that breaks down the principal elements of a REST approach into three steps. These introduce resources, http verbs, and hypermedia controls..." https://martinfowler.com/articles/richardsonMaturityModel.html

Volatile explained with Singleton example

"Volatile keyword in Java is used as an indicator to Java compiler and Thread that do not cache value of this variable and always read it from main memory ... A volatile variable can be used as an alternative way of achieving synchronization in Java in some cases, like Visibility. with volatile variable, it's guaranteed that all reader thread will see updated value of the volatile variable once write operation completed, without volatile keyword different reader thread may see different values ..." Moreo on Violate keyword & how to use it here:  https://javarevisited.blogspot.com/2011/06/volatile-keyword-java-example-tutorial.html