Wednesday, March 8, 2017

Update on my Gitconfig

Here is another update on my gitconfig:

[alias]
lg= log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
#quick look at all repo
loggsa = log --color --date-order --graph --oneline --decorate --simplify-by-decoration --all
#quick look at active branch (or refs pointed)
loggs = log --color --date-order --graph --oneline --decorate --simplify-by-decoration
#extend look at all repo
logga = log --color --date-order --graph --oneline --decorate --all
#extend look at active branch
logg = log --color --date-order --graph --oneline --decorate
#Look with date
logda = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\" --all
logd = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\"
#Look with relative date
logdra = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\" --all
logdr = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\"
loga = log --graph --color --decorate --all
view raw .gitconfig hosted with ❤ by GitHub

Saturday, March 4, 2017

REST Endpoint returning 404 without Exceptions

At some point in your REST endpoint design, you will need to return a non 200 response. Now, most implementations show how to implement this using exceptions. While this may seem like a nice approach (from a programming language point of view), exceptions can add overhead to the running JVM. This translates to ineffective use of resources of the JVM for supporting non 200 responses.

Here is a gist where you don't use exceptions to return non 200 responses:

@RequestMapping("/{surveyId}")
public Survey findSurvey(@PathVariable String surveyId, HttpServletResponse response) {
log.info("Querying survey {}", surveyId);
Survey survey = repository.get(surveyId);
if (survey == null) {
log.warn("Survey {} was not found!", surveyId);
response.setStatus(404);
}
return survey;
}

A few things to note from this snippet:
  1. This is a Spring Boot implementation (Boot makes things so much simple)
  2. The HttpServletResponse is injected by Boot (Spring MVC), no need of additional setup.
  3. Notice that the body return is null already, so the non 200 response makes more sense.
Please note that this is an implementation specific construct to support non 200 responses. Jersey and others also provide a non exceptional way to handle this scenario. Semantics of what the endpoint does (nouns non verbs, uniform contracts, interfaces, etc) are not part of the discussion. This is strictly an implementation description meant to support the abstraction defined by the given REST endpoint.