Last Updated: February 25, 2016
·
532
· baens

Awesome, simple, REST framework for Java

If you want a simple REST backend built in java, that is fully testable, and handles an amazing amount of the yak shaving, checkout Jersey

Here is an example of a end point implementation:

@Path("parameters")
@Produces(MediaType.APPLICATION_JSON)
public class ParameterResource {
    private final Repository _repo;

    @Inject
    public ParameterResource(Repository repo) {
        _repo = repo;
    }

    @GET
    public Iterable<Parameter> get(){
        return _repo.findAllParameters();
    }
}

This would create an endpoint at /parameters and when a HTTP GET is recieved, would produce JSON (as typed by the @Produces, you can do XML if you wanted, or what ever format!) in something like [{parameterId:1,name:'test'},{parameterId:2,name:'test2'}].