Category Archives: Programming

Writing REST APIs – CREATE/POST – Best Practices – Part II

Writing REST APIs – CREATE/POST – Best Practices – Part II

This is my second post on Writing REST APIs. Today the focus is on POST HTTP method. Basically POST method is used for create a resource. Sample Request : POST /users { “users” : [{ “firstName” : “Tom”, “lastName” : “Cruise” },{ “firstName” : “Tom”, “lastName” : “Hardy” }] } Sample Response : { “statusCode” :… Read More »

Writing REST APIs – CRUD – Request & Response – Best Practices – Part I

Writing REST APIs - CRUD - Request & Response - Part I

Writing REST APIs – CRUD – Request & Response – Best Practices – Part I

Writing REST APIs - CRUD - Request & Response - Part I

I am going to publish a series of posts  related to REST APIs standards and today we will see some details on designing the request and response for an API. So now we will assume we are going to write an API for user managements and we call this User API. When writing an API, the following… Read More »

Java – Break Filter Chain and Return Custom POJO Response from Servlet Filter

Java - Break Filter Chain and Return Custom POJO Response from Servlet Filter

Java – Break Filter Chain and Return Custom POJO Response from Servlet Filter

Java - Break Filter Chain and Return Custom POJO Response from Servlet Filter

Sample Servlet Filter : package com.application.test.security; import com.application.test.response.ErrorResponse; import com.fasterxml.jackson.databind.ObjectMapper; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class TestFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,ServletException { if(ANY CONDITION){ //ANY POJO CLASS ErrorResponse errorResponse = new ErrorResponse();… Read More »

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Sample Query : POST /test/test/_search { “query”: { “filtered”: { “filter”: { “bool”: { “must”: [{ “range”: { “dateOrTimeAttribute”: { “from”: “16:31:15”, “to”: “16:31:15||+10m” } } }] } } } } } Examples: “16:31:15||+10m” “16:31:15||+1d” “2016-02-02||-1M”  

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Maven Dependency : <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> <version>1.2</version> </dependency> Sample Java Program : package test; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; public class Test { public static void main(String[] args) { //Define Options Options options = new Options(); //Option Name – option1 //Has input value – true options.addOption(“option1”, true, “Option 1 Description”);… Read More »