JAX-RS To Metamug Resource

In this example we will see how a resource is written in JAX-RS and compare with the equivalent in Metamug.

Java API for RESTful Web Services (JAX-RS)

The current standard for writing REST APIs in java is JAX-RS. Though the popular spring framework follows its own annotations.

You can find multiple implementation for the standard.

and many others.

The folllowing example demonstrates how a typical GET request

/user?name=banana&quant=12&desc=fruit
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

@Path("/user")
public class UserService {

    @GET
    public Response getUsers(
        @QueryParam("name") String name,
        @QueryParam("quant") int quantity,
        @QueryParam("desc") String description) {

        return Response
           .status(200)
           .entity("{ itemName :" + name + ", itemQuantity : " + quantity
            + ", itemDescription :" + description + " }").build();

    }

}

Metamug Resource

The same resource can be written in metamug as follows.

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns="http://xml.metamug.net/resource/1.0" v="1.0">
    <Request method="GET">
        <Query>
            select $name "itemName", $quant "itemQuantity", $desc "itemDescription"
        </Query>     
    </Request>
</Resource>

Check the resource file docs for usage

Service-DAO-POJO-DTO-Repository-JDBC-JPA-...

But JAX-RS REST resources are not so simple.

Every resource in JAX-RS is backed by

Here is an example for this in spring boot