java/nekurak.net-rest/src/java/cz/frantovo/nekurak/rest/ClankyREST.java
author František Kučera <franta-hg@frantovo.cz>
Mon Apr 05 22:21:01 2010 +0200 (2010-04-05)
changeset 89 59ba044de164
parent 88 a5339bcce9a2
child 90 0967d5e3b470
permissions -rw-r--r--
Články – metody pro REST API.
     1 package cz.frantovo.nekurak.rest;
     2 
     3 import javax.ws.rs.Consumes;
     4 import javax.ws.rs.DELETE;
     5 import javax.ws.rs.GET;
     6 import javax.ws.rs.POST;
     7 import javax.ws.rs.PUT;
     8 import javax.ws.rs.Path;
     9 import javax.ws.rs.PathParam;
    10 import javax.ws.rs.Produces;
    11 
    12 @Path("clanek")
    13 public class ClankyREST {
    14 
    15     private static final String MIME_XML = "text/xml";
    16 
    17     /** Vypíšeme seznam všech článků v systému */
    18     @GET
    19     @Path("/")
    20     @Produces("text/plain")
    21     public String getClanky() {
    22 	return "tady bude seznam";
    23     }
    24 
    25     /** Získáme konkrétní článek */
    26     @GET
    27     @Path("/{id}")
    28     @Produces("text/plain")
    29     //@Produces(MIME_XML)
    30     public String ziskej(@PathParam("id") int id) {
    31 	return "jeden článek: " + id;
    32     }
    33 
    34     /**
    35      * Vložíme nový článek
    36      * @return ID založeného článku
    37      */
    38     @POST
    39     @Consumes(MIME_XML)
    40     @Produces("text/plain")
    41     public int zaloz() {
    42 	return 0;
    43     }
    44 
    45     /** Aktualizujeme článek */
    46     @PUT
    47     @Consumes(MIME_XML)
    48     @Path("/{id}")
    49     public void uloz(@PathParam("id") int id) {
    50     }
    51 
    52     /** Smažeme článek */
    53     @DELETE
    54     @Path("/{id}")
    55     public void smaz(@PathParam("id") int id) {
    56     }
    57 }