BrianMason Using Rest API-2
BrianMason Using Rest API-2
B. Mason
Netapp E-Series
+
Disclaimer
Opinion expressed here are mine and do not necessarily represent
Netapp
2
Who am I??
3
Agenda
4
+
Why we do care about the API?
• Other attributes
• Client/Server
• Stateless
• Cacheable
• Uniform
6
Why are they different/more useful ?
• REST IS SIMPLE
• Like SOAP and XMLRPC , its “Text Based”
• No weird binary formats to parse
• Easy to consume by any language
• Relies on standard compression algorithms for speed
+
Lets look at a Demo
8
+ Primer for REST
Technology
9
Definitions
HTTP – Hyper Text Transfer Protocol
Query String – Part of the URL after the question mark. Contains
key/value data
http://somehost.com/resource?key=value&key=value
10
HTTP Verbs
Client Server
HTTP GET
Host: somehost.domain.com
Accept: application/json
Accept-Langauge: en-us
Status: ok
Content-Type: application/json
{
“message”:”Hello REST”
}
12
Common HTTP Headers
14
Building a REST Server
15
Simple Servlet
HttpServletResp resp) {
PrintWriter out;
out=new PrintWriter(response.getOutputStream());
resp.setHeader("Content-Type","application/json");
out.println("{\"message\":\"Hello World\"}");
out.flush();
out.close();
}
}
16
JAX-RS
JSR 339
@Path("hello")
public class HelloJersey {
@GET
@Produces("application/json")
public ResponseOne handleGet(){
ResponseOne ret;
return ret;
}
}
18
Response Class - POJO
@XmlRootElement
public class ResponseOne implements Serializable{
private String message;
public ResponseOne() {
}
20
Swagger World
https://jax-rs-spec.java.net/
http://www.django-rest-framework.org/
http://swagger.io/
http://www.w3.org/Protocols/rfc2616/rfc2616.html
https://jcp.org/en/jsr/detail?id=339
https://jersey.java.net/
http://wiki.fasterxml.com/JacksonHome
29