describes how distributed data objects, or resources, can be defined and addressed, stressing the easy exchange of information and scalability.(Fischer 2013.)
g r a i l s . r e s t . R e s o u r c e @ R e s o u r c e ( u r i = ' / g r 8 l a d i e s ' ) c l a s s G r 8 L a d y { S t r i n g f i r s t S t r i n g l a s t }
m a p p i n g s . g r o o v y " / g r 8 l a d i e s " ( r e s o u r c e s : " g r 8 l a d y " ) " / g r 8 l a d i e s " ( r e s o u r c e s : " g r 8 l a d y " ) { " / c h a p t e r " ( c o n t r o l l e r : " c h a p t e r " , m e t h o d : " G E T " ) }
errors Code Description 2XX Successful 200 OK 4XX Client Error 400 Bad Request 403 Forbidden 404 Not Found 5XX Server Errors 500 Internal Server Error 502 Bad Gateway an exerpt fromhttp://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
s s G r 8 L a d y C o n t r o l l e r { s t a t i c a l l o w e d M e t h o d s = [ l i s t : " G E T " , s a v e : " P O S T " , u p d a t e : " P U T " ] }
a m p l e . c o m / r e s o u r c e / { i d } NOT h t t p : / / e x a m p l e . c o m / r e s o u r c e ? i d = a b c 1 2 3 NOT h t t p : / / e x a m p l e . c o m / r e s o u r c e / { i d } / ? a c t i o n = d e l e t e NOT h t t p : / / e x a m p l e . c o m / r e s o u r c e / a d d
r a i l s : m i m e : t y p e s : . . . j s o n : [ ' a p p l i c a t i o n / j s o n ' , ' t e x t / j s o n ' ] , . . . x m l : [ ' t e x t / x m l ' , ' a p p l i c a t i o n / x m l ' ]
another type returns a 406 (Not Acceptable) i m p o r t g r a i l s . r e s t . R e s o u r c e @ R e s o u r c e ( u r i = ' / g r 8 l a d i e s ' , f o r m a t s = [ ' j s o n ' ] ) c l a s s G r 8 L a d y { . . . }
to add any response formats for versioned mime types c l a s s G r 8 L a d y C o n t r o l l e r e x t e n d s R e s t f u l C o n t r o l l e r { s t a t i c r e s p o n s e F o r m a t s = [ ' j s o n ' , ' x m l ' ] }
i l s - a p p / i n i t / B o o t s t r a p . g r o o v y Usage i m p o r t g r a i l s . c o n v e r t e r s . J S O N c l a s s B o o t s t r a p { d e f i n i t = { s e r v l e t C o n t e x t - > J S O N . r e g i s t e r O b j e c t M a r s h a l l e r ( G r 8 L a d y ) { d e f r e t u r n A r r a y = [ : ] r e t u r n A r r a y [ ' f i r s t N a m e ' ] = i t . f i r s t r e t u r n A r r a y [ ' l a s t N a m e ' ] = i t . l a s t r e t u r n A r r a y [ ' c h a p t e r ' ] = i t . c h a p t e r ? . n a m e r e t u r n r e t u r n A r r a y } } } r e n d e r g r 8 l a d y a s J S O N
i l s - a p p / c o n f / s p r i n g / r e s o u r c e s . g r o o v y i m p o r t g r a i l s . c o n v e r t e r s . J S O N i m p o r t o r g . g r 8 l a d i e s . C h a p t e r M a r s h a l l e r b e a n s = { J S O N . r e g i s t e r O b j e c t M a r s h a l l e r ( n e w C h a p t e r M a r s h a l l e r ( ) ) }
s s G r 8 L a d y M a r s h a l l e r i m p l e m e n t s O b j e c t M a r s h a l l e r < J S O N > { p u b l i c b o o l e a n s u p p o r t s ( O b j e c t o b j e c t ) { r e t u r n o b j e c t i n s t a n c e o f G r 8 L a d y } p u b l i c v o i d m a r s h a l O b j e c t ( O b j e c t o b j e c t , X M L c o n v e r t e r ) { G r 8 L a d y g r 8 l a d y = ( G r 8 L a d y ) o b j e c t c o n v e r t e r . c h a r s g r 8 l a d y . d i s p l a y N a m e } }
the resource and navigation { " _ l i n k s " : { " s e l f " : { " h r e f " : " / g r 8 l a d i e s " } , " n e x t " : [ { " h r e f " : " / g r 8 l a d i e s ? p a g e = 2 " } ] } }
a i l s - a p p / c o n f / s p r i n g / r e s o u r c e s . g r o o v y i m p o r t g r a i l s . r e s t . r e n d e r . h a l . * b e a n s = { h a l G r 8 L a d y R e n d e r e r ( H a l J s o n R e n d e r e r , o r g . g r 8 l a d i e s . G r 8 L a d y ) }
- i - H " A c c e p t : a p p l i c a t i o n / h a l + j s o n " h t t p : / / l o c a l h o s t : 8 0 8 0 / g r 8 l a d i e s / 1 H T T P / 1 . 1 2 0 0 O K S e r v e r : A p a c h e - C o y o t e / 1 . 1 C o n t e n t - T y p e : a p p l i c a t i o n / h a l + j s o n ; c h a r s e t = I S O - 8 8 5 9 - 1 { " _ l i n k s " : { " s e l f " : { " h r e f " : " h t t p : / / l o c a l h o s t : 8 0 8 0 / g r 8 l a d i e s / 1 " , " h r e f l a n g " : " e n " , " t y p e " : " a p p l i c a t i o n / h a l + j s o n " } } , " n a m e " : " " G r a c e H o p p e r " " }
x a m p l e . c o m / r e s o u r c e ? o f f s e t = 0 & m a x = 1 0 d e f l i s t ( ) { L i s t g r 8 l a d i e s = G r 8 L a d y . l i s t ( m a x : p a r a m s . m a x , o f f s e t : p a r a m s . o f f s e t ) r e s p o n d [ r e s u l t s : g r 8 l a d i e s , m a x : p a r a m s . m a x , o f f s e t : p a r a m s . o f f s e t ] }
x a m p l e . c o m / v 1 / r e s o u r c e / { i d } Custom Header Content Type G E T h t t p s : / / e x a m p l e . c o m / r e s o u r c e v e r s i o n : 2 . 0 G E T h t t p s : / / e x a m p l e . c o m / r e s o u r c e A c c e p t : a p p l i c a t i o n / v n d . e x a m p l e . v 2 + j s o n
r c e ( u r i = ' / g r 8 l a d i e s / v 1 ' ) @ R e s o u r c e ( u r i = ' / g r 8 l a d i e s / v 2 ' ) Accept Header " / g r 8 l a d i e s " ( v e r s i o n : ' 1 . 0 ' , r e s o u r c e s : " g r 8 l a d y " , n a m e s p a c e : ' v 1 ' ) " / g r 8 l a d i e s " ( v e r s i o n : ' 2 . 0 ' , r e s o u r c e s : " g r 8 l a d y " , n a m e s p a c e : ' v 2 ' )
Ludovico. . Tuts+. 9 Jan 2013. Web Fielding, Roy. . 2000. "Representational State Transfer (REST)" "A Beginner’s Guide to HTTP and REST" Architectural Styles and the Design of Network-based Software Architectures