GET rfc5023#section-10 HTTP/1.1⏎ Host: tools.ietf.org⏎ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1⏎ Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8⏎ Accept-Language: en-us,en;q=0.5⏎ Accept-Encoding: gzip, deflate⏎ Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7⏎ Connection: keep-alive⏎ If-Modified-Since: Mon, 09 Jan 2012 22:47:46 GMT⏎ If-None-Match: "1827ba7-21df5-4b6202feb4880;4b6ff84c9e6cf"⏎ Cache-Control: max-age=0⏎ ⏎
public static void main(String[] args) throws Exception { // Setup the server Server server = new Server(8080); server.setHandler(new SimpleResourceServer()); server.start(); server.join(); }
public class SimpleResourceServer extends AbstractHandler { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { } ...
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { //Check whether we can handle request //Handle the request and write the output to response baseRequest.setHandled(true); } ...
RangeMatcher<MediaRange> acceptMatcher = new RangeMatcher<MediaRange>(new MediaRangeParser()); acceptMatcher.registerKnownType("text/plain"); acceptMatcher.registerKnownType("application/xml"); String request = "text/plain;q=0.5,text/html"; System.out.println(acceptMatcher.getBestMatch(request)); //Displays text/plain
Design a RESTFul web service to manage a list of contacts. This service exposes its data as Atom feeds.
Contacts have a first name, a last name, a name used for display, and an email address.
Contacts can be associated with different groups.
AtomPub is a recommendation that defines a protocol for publishing and editing Web Resources. The protocol is based on HTTP transfer of Atom-formatted representations.
This short introduction does not cover every single concept.
Check RFC 5023 for details.
Analogy: Blog post
Represented as atom entries.
Support GET, PUT, DELETE
Analogy: Blog
Represented as atom feeds.
Support GET, POST
Entry point of the service
Goal: designing the contacts list REST Service.
That is, mapping the resources to URIs and semantics.
E.g.
Resource | Path | Method | Semantics |
---|---|---|---|
Root | / | GET | Retreives the contacts collection |
final Entry entry = Abdera.getInstance() .getFactory().newEntry(); entry.setTitle("Title); entry.setEdited(new Date()); entry.setId("id:1234567890"); entry.addLink("http://example.org/", "edit"); entry.addLink("http://example.org/", "self");
final Feed contactsFeed = Abdera.getInstance(). getFactory().newFeed(); contactsFeed.setTitle("My Feed"); contactsFeed.addLink("http://www.example.org/", Relations.SELF); contactsFeed.setId("id:0987654321"); contactsFeed.setUpdated(new Date()); contactsFeed.addEntry(entry1); contactsFeed.addEntry(entry2); contactsFeed.addEntry(entry3);
Java specification for defining REST-style services
@Path("/a/b/c/resource") public class ResourceImpl { @GET @Produces("text/plain") public Response getSomething() { final String resp = "Hello"; return Response.ok(resp).build(); }
@PUT @Produces("text/plain") @Consumes("text/plain") public Response getSomething(final Reader data) { //Read from data //Build a response final String resp = "Hello"; return Response.ok(resp).build(); }
@Path("/a/b/c/resource/{variable1}/{variable2}") public class ResourceImpl { @Get @Produces("text/plain") public Response getSomething( @PathParam("variable1" final String var1) @PathParam("variable2" final String var2) ) { //Build a response final String resp = "Hello " + var1 + var2; return Response.ok(resp).build(); }
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |