REST Webservices Made Simple Jackson Thompson jaxenjaxennet I write code and do other stuff Background info Real quick lets go over what REST is and a couple background technologies Stay away from rabbit holes ID: 142148
Download Presentation The PPT/PDF document "Or, Hey can’t we just do it using HTTP..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Or, Hey can’t we just do it using HTTP for the envelope?
REST:
Webservices
Made SimpleSlide2
Jackson Thompson
jaxen@jaxen.net
I write code and do other stuffSlide3
Background info
Real quick, let’s go over what REST is and a couple background technologies. Stay away from rabbit holes!Slide4
REST: What and Why
EDI
Internet – HTTP
Web Services
SOAP – S? Object Access Protocol
REST –
REpresentational
State Transfer
Stateless
Maps CRUD
to HTTP Methods
Multiple data formats
(Most Popular - XML
, JSON)
No
RPC
WADLSlide5
HTTP in 2 minutes
HTTP 1.1 (http 2.0, it does matter for this subject)
STATELESS – Request / Response
Text Protocol
Requests
URI – protocol://server.domain.tld/path/resource?query=string&name=value
Methods
No Data in request body – GET, DELETE, head, option, connect
Data in request body – POST, PUT, patch
Headers – Host is required
Content-type – application/xml, application/
json
Authentication
JSessionId
– don’t careSlide6
Http in 2 minutes
Response
Status Codes
200 – Success
300 – Redirect
400 – Client Issue
500 – Server Issue
Header
BodySlide7
XML in 1 minute
XML-
EXtensible
Markup Language
< > around Tags
</ end Tag
Nesting
Elements
AttributesSlide8
JSON in 1 minute
JSON -
J
ava
S
cript
O
bject
N
otation
Lightweight
{
Name :
Value }
[ array ]Slide9
XMLHttpRequest
The Server Really Doesn’t Care!Slide10
Let’s Code
The way to learn code is to write code!Slide11
ToolsCan’t build without tools
Eclipse
Netbeans
Jersey – JAX-RS reference implementation
Tomcat
8.0
JDK 8
Chrome – With JSON plugin
MariaDB
SoapUI
–
SmartBear
This is not the
only tool
set available!Slide12
JAXB – If I wanted to parse text I’d write it in perl
Java Architecture for XML Binding
Turn Objects into XML and vise-versa
Marshall and
Unmarshall
Annotation Based
Can generate classes from a Schema Slide13
JAXB -Coding
JAXBContext
–
jaxb.index
/
ObjectFactory
Marshaller
–
marshal to SAX, DOM,
OutputStream
, Writer
Annontations
XMLRootElement
XmlAccessorType
XmlElementWrapper
XmlElement
XmlList
XmlAttributeSlide14
Jax-RSJersey Reference Implementation
Java API for RESTful Web Services
Uses JAXB
Application /
ResourceConfig
Resources
Client
Filters / Interceptors
Web Application Description Language (WADL)Slide15
Resource
Annotations
Path
Method GET, POST, PUT, DELETE, HEAD
Param
,
PathParam
,
QueryParam
Consumes, Produces
ProviderSlide16
Filters and Interceptors
Client or Server Side
Inbound or Outbound
Filters modify Header, Entity, Request/Response Parameters
Interceptors modify input / output Streams