Archive for May, 2015

 

Basic REST web service example ..

May 08, 2015 in Java, REST, Web, WebServices

From: http://getj2ee.over-blog.com/article-tutorial-rest-with-spring-mvc-and-maven-97283997.html


@Controller // --> Declare a Spring MVC Controller

@RequestMapping("/computer") // --> Map an URI with a controller or a method

@PathVariable // --> Read a variable in an Uri and assign this value to a java variable

@RequestBody // --> Declare a Pojo class to map the http request body  

@ResponseBody // --> Declare a Pojo class to generate Json content to return to the http client


// Declaration as this class as a controller
@Controller 

// Declaration that this controller handles requests on uri */computer
@RequestMapping("/computer") 

public class ComputerController {
 
  // Stores computers
  private static final ComputerStorage computerStorage = new ComputerStorage();
 
  // Declare a method that handle all GET request on */computer
  @RequestMapping(method = RequestMethod.GET)

  // Return a list of computer to the http client
  @ResponseBody public List<Computer> getComputers() {
   return computerStorage.getAll();
  }
}

node.js learning with learnyounode .. solutions ..

May 08, 2015 in javascript, node.js

Exercise 4, asynchronous (async) file processing ..

From: https://github.com/JeffPaine/learnyounode-solutions


var countLines = function (err, fileBuffer){
  // console.log(fileBuffer);
  console.log(fileBuffer.split('\n').length);
};

fs.readFile(process.argv[2], 'utf8', countLines);