REZA LESMANA
                               Universitas Gunadarma




Saturday, February 5, 2011
REST
                             Using Restlet Framework
Saturday, February 5, 2011
REST
                    Representational State Transfer



Saturday, February 5, 2011
WHAT IS REST?
               GAYA ARSITEKTUR SOFTWARE UNTUK ARSITEKTUR
                        APLIKASI BERBASIS JARINGAN

                                      BASICALLY
                             WEB SERVICES ARCHITECTURE



Saturday, February 5, 2011
WHY USE REST?
                             UNIFORM INTERFACE




    SEMUA KOMPONEN APLIKASI DALAM WEB SERVICES
       BERINTERAKSI DENGAN CARA YANG SAMA


Saturday, February 5, 2011
UNIFORM INTERFACE
                                one of the feature of REST




Saturday, February 5, 2011
UNIFORM INTERFACE
                             Resource Identification [1]

                                   RESOURCE
                informasi yang dibutuhkan oleh user untuk
                menjalankan proses bisnis dari suatu aplikasi


Saturday, February 5, 2011
UNIFORM INTERFACE
                             Resource Identification [2]

                   Uniform Resource Identifier
                             (URI)
                                  Contoh : HTTP URL


Saturday, February 5, 2011
UNIFORM INTERFACE
                              Resource Identification [3]
                                        URI Template

                             http://contohaja.com/message/{index}



Saturday, February 5, 2011
RESTLET FRAMEWORK
                                 application building block




Saturday, February 5, 2011
RESTLET FRAMEWORK
                                   servlet configuration (web.xml)
                              <!-- Application class name -->
                              <context-param>
                                 <param-name>org.restlet.application</param-name>
                                 <param-value>
                                     com.helloworld.main.MainApplication
                                 </param-value>
                              </context-param>

                              <!-- Restlet adapter -->
                              <servlet>
                                 <servlet-name>RestletServlet</servlet-name>
                                 <servlet-class>
                                     org.restlet.ext.servlet.ServerServlet
                                 </servlet-class>
                              </servlet>

                              <!-- Catch all requests -->
                              <servlet-mapping>
                                 <servlet-name>RestletServlet</servlet-name>
                                 <url-pattern>/*</url-pattern>
                              </servlet-mapping>



Saturday, February 5, 2011
UNIFORM INTERFACE
                              Resource Identification [4]
                                 aplikasi penyimpanan pesan dalam stack


    • Daftar                 Pesan --->   • “/” --->   MessagesResource

    • Top           of Stack --->         • “/message/    ---> MessageResource

    • Pesan Tunggal                --->   • “/message/{index}   ---> MessageResource



Saturday, February 5, 2011
RESTLET FRAMEWORK
                              MainApplication
       public class MainApplication extends Application {

       	      public MainApplication(Context parentContext) {
       	      	 super(parentContext);		
       	      }
       	
       	      @Override
       	      public synchronized Restlet createInboundRoot() {
       	      	 Router router = new Router(getContext());
       	      	
       	      	 router.attach("/", MessagesResource.class);
       	      	 router.attach("/message/", MessageResource.class);
       	      	 router.attach("/message/{messageIndex}", MessageResource.class);
       	      	
       	      	 return router;
       	      }
       }

Saturday, February 5, 2011
UNIFORM INTERFACE
      Manipulation Through Representation [1]

                                REPRESENTATION

                             representasi dari resource


Saturday, February 5, 2011
RESTLET FRAMEWORK
                                 application building block




Saturday, February 5, 2011
UNIFORM INTERFACE
      Manipulation Through Representation [2]
                              HTTP METHOD as Popular Practices


   • HTTP                POST ---> • membuat Resource baru (Create)

   • HTTP                GET --->    • mendapatkan   Resource (Read)

   • HTTP                PUT --->    • mengubah   Resource (Update)

   • HTTP                DELETE ---> • menghapus Resource (Delete)


Saturday, February 5, 2011
UNIFORM INTERFACE
      Manipulation Through Representation [3]
                                        Another Protocol?


    • Gunakan     standar protokol komunikasi sesuai dengan
        spesifikasinya

    • Perhatikan             Safety dan Idempotency dari method

              • Safety       : tidak menghasilkan “efek samping” pada resource

              • Idempotency         : dilakukan berulang-ulang hasilnya sama

Saturday, February 5, 2011
UNIFORM INTERFACE
      Manipulation Through Representation [4]
                       Standardized Document Structure as Representation


                             • XHTML        • MPEG

                             • XML          • MP3

                             • Atom   Pub   • AVI

                             • OData        • Text/Audio/Video   Streaming


Saturday, February 5, 2011
UNIFORM INTERFACE
      Manipulation Through Representation [5]
                                      Not Only HTTP


                             TEXT/AUDIO/VIDEO STREAMING
                                     Contoh : VoIP

                                   Using SIP or XMPP



Saturday, February 5, 2011
RESTLET FRAMEWORK
                              MainApplication
       public class MainApplication extends Application {

       	      public MainApplication(Context parentContext) {
       	      	 super(parentContext);		
       	      }
       	
       	      @Override
       	      public synchronized Restlet createInboundRoot() {
       	      	 Router router = new Router(getContext());
       	      	
       	      	 router.attach("/", MessagesResource.class);
       	      	 router.attach("/message/", MessageResource.class);
       	      	 router.attach("/message/{messageIndex}", MessageResource.class);
       	      	
       	      	 return router;
       	      }
       }

Saturday, February 5, 2011
RESTLET FRAMEWORK
      Manipulation Through Representation [1]
                       public class MessageResource extends ServerResource {
                       	
                       	 @Post
                       	 public Representation addMessage(Representation entity) {
                       	 	 StringRepresentation representation = null;
                       	 	
                       	 	 String result = "";
                       	 	 try {
                       	 	 	 result = HelloBusiness.create(entity.getText());
                       	 	 } catch (IOException e) {
                       	 	 	 setStatus(Status.SERVER_ERROR_INTERNAL );
                       	 	 }
                       	 	
                       	 	 representation = new StringRepresentation
                       	 	 	 (result, MediaType.APPLICATION_XML);
                       	 	
                       	 	 return representation;	
                       	 }

Saturday, February 5, 2011
RESTLET FRAMEWORK
      Manipulation Through Representation [2]
                  @Get("xml")
           	      public Representation get(){
           	      	 String index = (String)getRequest().getAttributes().get("messageIndex");
           	      	 StringRepresentation representation = null;
           	      	 String result = "";
           	      	 try{
           	      	 	 if(index != "" && index != null){
           	      	 	 	 result = HelloBusiness.get(Integer.parseInt(index));
           	      	 	 }else{
           	      	 	 	 result = HelloBusiness.get();
           	      	 	 }
           	      	 	 representation = new StringRepresentation
           	      	 	 	 	 	 	 (result, MediaType.APPLICATION_XML);
           	      	 	 return representation;
           	      	 }catch(Exception e){
           	      	 	 setStatus(Status.CLIENT_ERROR_NOT_FOUND);
           	      	 	 representation = new StringRepresentation
           	      	 	 	 	 	 	 ("no item found", MediaType.TEXT_PLAIN);
           	      	 	 return representation;	 	
           	      	 }
           	      }

Saturday, February 5, 2011
RESTLET FRAMEWORK
      Manipulation Through Representation [3]
                       	     @Put
                       	     public Representation put(Representation entity){
                       	     	 StringRepresentation representation = null;
                       	     	
                       	     	 String result = "";
                       	     	 try {
                       	     	 	
                       	     	 	 result = HelloBusiness.update(entity.getText());
                       	     	 	
                       	     	 } catch (IOException e) {
                       	     	 	 setStatus(Status.SERVER_ERROR_INTERNAL );
                       	     	 }
                       	     	
                       	     	 representation = new StringRepresentation
                       	     	 	 	 	 	 	 (result, MediaType.APPLICATION_XML);
                       	     	
                       	     	 return representation;
                       	     }
Saturday, February 5, 2011
RESTLET FRAMEWORK
      Manipulation Through Representation [4]
            	     @Delete
            	     public Representation delete(){
            	     	 StringRepresentation representation = null;
            	     	 String result = "";
            	     	 try {
            	     	 	 result = HelloBusiness.delete();
            	     	 }catch(NoMoreItemException ne){
            	     	 	 setStatus(Status.CLIENT_ERROR_FORBIDDEN);
            	     	 	 representation = new StringRepresentation
            	     	 	 	 	 ("Tidak boleh, udah kosong", MediaType.TEXT_PLAIN);
            	     	 	 return representation;
            	     	 }
            	     	 representation = new StringRepresentation
            	     	 	 	 	 	 	 (result, MediaType.APPLICATION_XML);
            	     	 return representation;
            	     }


Saturday, February 5, 2011
UNIFORM INTERFACE
                             Self-Descriptive Messages [1]

                                    TWO FACTORS

                            The Protocol Message
                    The Media Type (Type of Representation)

Saturday, February 5, 2011
UNIFORM INTERFACE
                             Self-Descriptive Messages [2]
                                  The Protocol Message

    • HTTP                   Header --> Content Negotiation
              •    Contoh :        Accept : application/xml

    • Status                 Respon :
         •   Contoh :            HTTP 1.1 / 200 OK ,HTTP 1.1 / 403 FORBIDDEN


Saturday, February 5, 2011
UNIFORM INTERFACE
                             Self-Descriptive Messages [3]
                                       The Media Type
         • Struktur             Dokumen Bisa Mudah Diolah
         • Contoh              :
                    • XML       (application/xml)
                    • Atom         Pub (application/atom+xml)
Saturday, February 5, 2011
Contoh MediaType XML
            <messages>
              <message>
                     <messageid>120</messageid>
                     <author>Reza</author>
                     <created>2011/02/04 08:20:12</created>
                     <value>Hello, World!</value>
                     <link>/message/120</link>
              <message>
              ........
              ........
            <messages>

Saturday, February 5, 2011
Contoh MediaType Atom
 <entry>
    <id>urn:uuid:95506d98-aae9-4d34-a8f4-1ff30bece80c</id>
    <title type=ʹ′ʹ′textʹ′ʹ′>product created</title>
    <updated>2009-07-05T10:25:00Z</updated>
    <link rel=ʹ′ʹ′selfʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/notifications/95506d98-aae9-4d34-
    a8f4-1ff30bece80cʹ′ʹ′/>
    <link rel=ʹ′ʹ′relatedʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/527ʹ′ʹ′/>
    <category scheme=ʹ′ʹ′http://starbucks.com/products/categories/typeʹ′ʹ′ term=ʹ′ʹ′productʹ′ʹ′/>
    <category scheme=ʹ′ʹ′http://starbucks.com/products/categories/statusʹ′ʹ′ term=ʹ′ʹ′newʹ′ʹ′/>
    <content type=ʹ′ʹ′application/vnd.starbucks+xmlʹ′ʹ′>
        <product xmlns=ʹ′ʹ′http://schemas.starbucks.com/productʹ′ʹ′
                       href=ʹ′ʹ′http://starbucks.com/products/527ʹ′ʹ′>
        <name>Fairtrade Roma Coffee Beans</name>
        <size>1kg</size>
        <price>10</price>
        <currency>$</currency>
        </product>
    </content>
 </entry>

Saturday, February 5, 2011
RESTLET FRAMEWORK
                             Self-Descriptive Message [1]
           @Get("xml")
           	 public Representation get(){
           	 	 String index = (String)getRequest().getAttributes().get("messageIndex");
           	 	 StringRepresentation representation = null;
           	 	 String result = "";
           	 	 try{
           	 	 	 if(index != "" && index != null){
           	 	 	 	 result = HelloBusiness.get(Integer.parseInt(index));
           	 	 	 }else{
           	 	 	 	 result = HelloBusiness.get();
           	 	 	 }
           	 	 	 representation = new StringRepresentation
           	 	 	 	 	 	 	 (result, MediaType.APPLICATION_XML);
           	 	 	 return representation;
           	 	 }catch(NotFoundException e){
           	 	 	 setStatus(Status.CLIENT_ERROR_NOT_FOUND);
           	 	 	 representation = new StringRepresentation
           	 	 	 	 	 	 	 ("no item found", MediaType.TEXT_PLAIN);
           	 	 	 return representation;	 	
           	 	 }
           	 }

Saturday, February 5, 2011
RESTLET FRAMEWORK
                             Self-Descriptive Message [2]
                                 <messages>
                                 <request>GET : ALL</request>
                                 <message>
                                 	 <request>GET</request>
                                 	 <value>Hello, World!</value>
                                 	 <link>/message/0</link>
                                 </message>
                                 <message>
                                 	 <request>GET</request>
                                 	 <value>Halo, Dunia!</value>
                                 	 <link>/message/1</link>
                                 </message>
                                 <message>
                                 	 <request>GET</request>
                                 	 <value>Apa Kabar?</value>
                                 	 <link>/message/2</link>
                                 </message>
                                 </messages>

Saturday, February 5, 2011
Saturday, February 5, 2011
UNIFORM INTERFACE
      Hypermedia as The Engine of Application
             State (HATEOAS) [1]

                                     or
                             Hypermedia constraints



Saturday, February 5, 2011
UNIFORM INTERFACE
                             Hypermedia Constraint [1]


    • Inti          dari Representational State Transfer
    • Menyatukan     informasi proses bisnis dalam
        representasi resource



Saturday, February 5, 2011
UNIFORM INTERFACE
                             Hypermedia Constraint [2]
                    explains why named as “representational state transfer”




Saturday, February 5, 2011
UNIFORM INTERFACE
                             Hypermedia Constraint [3]
                                 execution of business process


                    “Consumers in a hypermedia system cause state
                    transitions by visiting and manipulating resource
                    state. Interestingly, the application state changes that
                    result from a consumer driving a hypermedia system
                    resemble the execution of a business process. This
                    suggests that our services can advertise workflows
                    using hypermedia.” - Jim Webber - REST In Practice




Saturday, February 5, 2011
UNIFORM INTERFACE
                             Hypermedia Constraint [3]
                                        Best Practices



    • Menambahkan       informasi possible next states
        langsung di dalam Representation
    • Caranya                (untuk saat ini) :
                    • possible   next states ----> hyperlinks


Saturday, February 5, 2011
UNIFORM INTERFACE
                             Hypermedia Constraint [4]
                                                      examples
                              <entry>
                              <order xmlns=ʹ′ʹ′http://schemas.starbucks.comʹ′ʹ′>
                              <location>takeAway</location>
                              <item>
                                  <name>latte</name>
                                  <quantity>1</quantity>
                                  <milk>whole</milk>
                                  <size>small</size>
                              </item>
                              <cost>2.0</cost>
                              <status>payment-expected</status>
                              <link rel=ʹ′ʹ′http://relations.restbucks.com/paymentʹ′ʹ′
                                      href=ʹ′ʹ′https://restbucks.com/payment/1234ʹ′ʹ′/>
                              <link rel=ʹ′ʹ′http://relations.restbucks.com/special-offerʹ′ʹ′
                                      href=ʹ′ʹ′http://restbucks.com/offers/cookie/1234ʹ′ʹ′/>
                              </entry>

Saturday, February 5, 2011
UNIFORM INTERFACE
                             Hypermedia Constraint [5]
                               hypermedia support in MediaType

    • Lebih baik jangan gunakan MediaType XML untuk
        menambahkan hyperlinks di dalamnya.
        •   Tidak ada dukungan langsung (native link tag) untuk hyperlinks

    • Gunakan                 Hypermedia Types (-Mike Amundsen)
                    • Contoh     : Atom
                    • http://amundsen.com/hypermedia/
Saturday, February 5, 2011
RESTLET FRAMEWORK
                             Hypermedia Constraints [1]

    • Native    support untuk mempermudah manajemen
        hypermedia constraints terdapat pada Restlet
        versi 2.1 (dalam pengembangan)
    • Solusi                 : Tambahkan secara manual !     :D
    • Solusi                 : Pakai versi 2.1 dengan resiko sendiri


Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                                  SOCIAL COMMERCE [1]


    • Indeks Aplikasi              Memuat :

              • Daftar Toko         Online (dengan link masing-masing)

              • Link         ke User Profile

              • Link         ke Pengaturan Toko Online milik user




Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                                    SOCIAL COMMERCE [2]


    • Masuk                  ke salah satu Toko Online (melalui link). Memuat :

              • Profil          singkat penjual (dengan link ke profil lengkap)

              • Daftar   Deskripsi Singkat Produk (dengan link masing-
                   masing untuk deskripsi lengkap)

              • Link          ke Indeks


Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                                  SOCIAL COMMERCE [3]



    • Lihat            deskripsi lengkap produk (melalui link). Memuat :

              • Informasi        produk

              • Link         untuk memesan

              • Link         kembali ke Toko Online



Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                             SOCIAL COMMERCE [4]




Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                             SOCIAL COMMERCE [5]




Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                             SOCIAL COMMERCE [6]




Saturday, February 5, 2011
CONTOH APLIKASI LAIN
                             SOCIAL COMMERCE [7]




Saturday, February 5, 2011
THANK YOU !

                             QUESTION?




Saturday, February 5, 2011

More Related Content

PPT
plsql les03
PPT
plsql les02
PDF
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
ODP
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
PPT
Plsql les04
PPT
plsql Les05
PDF
PPTX
File connector mule
plsql les03
plsql les02
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
Plsql les04
plsql Les05
File connector mule

What's hot (18)

ODP
Mule ESB SMTP Connector Integration
PPT
09 Managing Dependencies
PPTX
Mule Esb Data Weave
PPTX
Junit in mule demo
PPT
Baocao Web Tech Java Mail
PPT
11 Understanding and Influencing the PL/SQL Compilar
PDF
Lecture11 b
PDF
PHP Oracle Web Applications by Kuassi Mensah
PPTX
Using SP Metal for faster share point development
PDF
Jersey and JAX-RS
PPTX
Getting modular with OSGI
PPTX
Mule system properties
PPTX
Mule testing
PDF
Php Applications with Oracle by Kuassi Mensah
PPTX
Mule Collection Splitter
PDF
Oracle sql & plsql
ODP
RestFull Webservices with JAX-RS
PDF
Force.com migration utility
Mule ESB SMTP Connector Integration
09 Managing Dependencies
Mule Esb Data Weave
Junit in mule demo
Baocao Web Tech Java Mail
11 Understanding and Influencing the PL/SQL Compilar
Lecture11 b
PHP Oracle Web Applications by Kuassi Mensah
Using SP Metal for faster share point development
Jersey and JAX-RS
Getting modular with OSGI
Mule system properties
Mule testing
Php Applications with Oracle by Kuassi Mensah
Mule Collection Splitter
Oracle sql & plsql
RestFull Webservices with JAX-RS
Force.com migration utility
Ad

Viewers also liked (7)

PPTX
Sistem Informasi & Aplikasinya
PPTX
Sistem informasi dalam organisasi
PPT
Revolusi mental dan konsep visi serta misi jokowi jusuf kalla 2014
PPTX
Asking and getting permission
DOC
Penulisan rujukan mengikut format apa contoh (1)
PPT
The philosophical foundations of education
PPTX
Education at a Glance 2014 - Key Findings
Sistem Informasi & Aplikasinya
Sistem informasi dalam organisasi
Revolusi mental dan konsep visi serta misi jokowi jusuf kalla 2014
Asking and getting permission
Penulisan rujukan mengikut format apa contoh (1)
The philosophical foundations of education
Education at a Glance 2014 - Key Findings
Ad

Similar to Rest dengan restlet (20)

PPTX
JAX-RS 2.0 and OData
PPTX
Introduction to Wildfly 8 - Marchioni
PPT
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
PDF
Why Laravel?
PDF
03.eGovFrame Runtime Environment Training Book Supplement
PDF
Building RESTful Services with WCF 4.0
PDF
Philly Spring UG Roo Overview
PDF
XML-RPC (XML Remote Procedure Call)
PDF
The Solar Framework for PHP
PPTX
The NuGram approach to dynamic grammars
PDF
4_598113hhhhhhhhhhhhhhhhhhhhhhh0134529250346.pdf
PDF
Native REST Web Services with Oracle 11g
PDF
JavaEE6 my way
PDF
Introduction to java servlet 3.0 api javaone 2008
PDF
Java Enterprise Edition 6 Overview
PDF
CDI, Seam & RESTEasy: You haven't seen REST yet!
PDF
04.egovFrame Runtime Environment Workshop
PDF
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
PDF
Network Device Database Management with REST using Jersey
PPTX
Overview of RESTful web services
JAX-RS 2.0 and OData
Introduction to Wildfly 8 - Marchioni
JavaOne 2009 - TS-5276 - RESTful Protocol Buffers
Why Laravel?
03.eGovFrame Runtime Environment Training Book Supplement
Building RESTful Services with WCF 4.0
Philly Spring UG Roo Overview
XML-RPC (XML Remote Procedure Call)
The Solar Framework for PHP
The NuGram approach to dynamic grammars
4_598113hhhhhhhhhhhhhhhhhhhhhhh0134529250346.pdf
Native REST Web Services with Oracle 11g
JavaEE6 my way
Introduction to java servlet 3.0 api javaone 2008
Java Enterprise Edition 6 Overview
CDI, Seam & RESTEasy: You haven't seen REST yet!
04.egovFrame Runtime Environment Workshop
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
Network Device Database Management with REST using Jersey
Overview of RESTful web services

Recently uploaded (20)

PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Modernising the Digital Integration Hub
PPT
Geologic Time for studying geology for geologist
PDF
CloudStack 4.21: First Look Webinar slides
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
STKI Israel Market Study 2025 version august
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
A review of recent deep learning applications in wood surface defect identifi...
Consumable AI The What, Why & How for Small Teams.pdf
Improvisation in detection of pomegranate leaf disease using transfer learni...
UiPath Agentic Automation session 1: RPA to Agents
Comparative analysis of machine learning models for fake news detection in so...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Modernising the Digital Integration Hub
Geologic Time for studying geology for geologist
CloudStack 4.21: First Look Webinar slides
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Flame analysis and combustion estimation using large language and vision assi...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
sbt 2.0: go big (Scala Days 2025 edition)
STKI Israel Market Study 2025 version august
Developing a website for English-speaking practice to English as a foreign la...
Final SEM Unit 1 for mit wpu at pune .pptx
Getting started with AI Agents and Multi-Agent Systems
OpenACC and Open Hackathons Monthly Highlights July 2025
Benefits of Physical activity for teenagers.pptx
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx

Rest dengan restlet

  • 1. REZA LESMANA Universitas Gunadarma Saturday, February 5, 2011
  • 2. REST Using Restlet Framework Saturday, February 5, 2011
  • 3. REST Representational State Transfer Saturday, February 5, 2011
  • 4. WHAT IS REST? GAYA ARSITEKTUR SOFTWARE UNTUK ARSITEKTUR APLIKASI BERBASIS JARINGAN BASICALLY WEB SERVICES ARCHITECTURE Saturday, February 5, 2011
  • 5. WHY USE REST? UNIFORM INTERFACE SEMUA KOMPONEN APLIKASI DALAM WEB SERVICES BERINTERAKSI DENGAN CARA YANG SAMA Saturday, February 5, 2011
  • 6. UNIFORM INTERFACE one of the feature of REST Saturday, February 5, 2011
  • 7. UNIFORM INTERFACE Resource Identification [1] RESOURCE informasi yang dibutuhkan oleh user untuk menjalankan proses bisnis dari suatu aplikasi Saturday, February 5, 2011
  • 8. UNIFORM INTERFACE Resource Identification [2] Uniform Resource Identifier (URI) Contoh : HTTP URL Saturday, February 5, 2011
  • 9. UNIFORM INTERFACE Resource Identification [3] URI Template http://contohaja.com/message/{index} Saturday, February 5, 2011
  • 10. RESTLET FRAMEWORK application building block Saturday, February 5, 2011
  • 11. RESTLET FRAMEWORK servlet configuration (web.xml) <!-- Application class name --> <context-param> <param-name>org.restlet.application</param-name> <param-value> com.helloworld.main.MainApplication </param-value> </context-param> <!-- Restlet adapter --> <servlet> <servlet-name>RestletServlet</servlet-name> <servlet-class> org.restlet.ext.servlet.ServerServlet </servlet-class> </servlet> <!-- Catch all requests --> <servlet-mapping> <servlet-name>RestletServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> Saturday, February 5, 2011
  • 12. UNIFORM INTERFACE Resource Identification [4] aplikasi penyimpanan pesan dalam stack • Daftar Pesan ---> • “/” ---> MessagesResource • Top of Stack ---> • “/message/ ---> MessageResource • Pesan Tunggal ---> • “/message/{index} ---> MessageResource Saturday, February 5, 2011
  • 13. RESTLET FRAMEWORK MainApplication public class MainApplication extends Application { public MainApplication(Context parentContext) { super(parentContext); } @Override public synchronized Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/", MessagesResource.class); router.attach("/message/", MessageResource.class); router.attach("/message/{messageIndex}", MessageResource.class); return router; } } Saturday, February 5, 2011
  • 14. UNIFORM INTERFACE Manipulation Through Representation [1] REPRESENTATION representasi dari resource Saturday, February 5, 2011
  • 15. RESTLET FRAMEWORK application building block Saturday, February 5, 2011
  • 16. UNIFORM INTERFACE Manipulation Through Representation [2] HTTP METHOD as Popular Practices • HTTP POST ---> • membuat Resource baru (Create) • HTTP GET ---> • mendapatkan Resource (Read) • HTTP PUT ---> • mengubah Resource (Update) • HTTP DELETE ---> • menghapus Resource (Delete) Saturday, February 5, 2011
  • 17. UNIFORM INTERFACE Manipulation Through Representation [3] Another Protocol? • Gunakan standar protokol komunikasi sesuai dengan spesifikasinya • Perhatikan Safety dan Idempotency dari method • Safety : tidak menghasilkan “efek samping” pada resource • Idempotency : dilakukan berulang-ulang hasilnya sama Saturday, February 5, 2011
  • 18. UNIFORM INTERFACE Manipulation Through Representation [4] Standardized Document Structure as Representation • XHTML • MPEG • XML • MP3 • Atom Pub • AVI • OData • Text/Audio/Video Streaming Saturday, February 5, 2011
  • 19. UNIFORM INTERFACE Manipulation Through Representation [5] Not Only HTTP TEXT/AUDIO/VIDEO STREAMING Contoh : VoIP Using SIP or XMPP Saturday, February 5, 2011
  • 20. RESTLET FRAMEWORK MainApplication public class MainApplication extends Application { public MainApplication(Context parentContext) { super(parentContext); } @Override public synchronized Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/", MessagesResource.class); router.attach("/message/", MessageResource.class); router.attach("/message/{messageIndex}", MessageResource.class); return router; } } Saturday, February 5, 2011
  • 21. RESTLET FRAMEWORK Manipulation Through Representation [1] public class MessageResource extends ServerResource { @Post public Representation addMessage(Representation entity) { StringRepresentation representation = null; String result = ""; try { result = HelloBusiness.create(entity.getText()); } catch (IOException e) { setStatus(Status.SERVER_ERROR_INTERNAL ); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; } Saturday, February 5, 2011
  • 22. RESTLET FRAMEWORK Manipulation Through Representation [2] @Get("xml") public Representation get(){ String index = (String)getRequest().getAttributes().get("messageIndex"); StringRepresentation representation = null; String result = ""; try{ if(index != "" && index != null){ result = HelloBusiness.get(Integer.parseInt(index)); }else{ result = HelloBusiness.get(); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }catch(Exception e){ setStatus(Status.CLIENT_ERROR_NOT_FOUND); representation = new StringRepresentation ("no item found", MediaType.TEXT_PLAIN); return representation; } } Saturday, February 5, 2011
  • 23. RESTLET FRAMEWORK Manipulation Through Representation [3] @Put public Representation put(Representation entity){ StringRepresentation representation = null; String result = ""; try { result = HelloBusiness.update(entity.getText()); } catch (IOException e) { setStatus(Status.SERVER_ERROR_INTERNAL ); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; } Saturday, February 5, 2011
  • 24. RESTLET FRAMEWORK Manipulation Through Representation [4] @Delete public Representation delete(){ StringRepresentation representation = null; String result = ""; try { result = HelloBusiness.delete(); }catch(NoMoreItemException ne){ setStatus(Status.CLIENT_ERROR_FORBIDDEN); representation = new StringRepresentation ("Tidak boleh, udah kosong", MediaType.TEXT_PLAIN); return representation; } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; } Saturday, February 5, 2011
  • 25. UNIFORM INTERFACE Self-Descriptive Messages [1] TWO FACTORS The Protocol Message The Media Type (Type of Representation) Saturday, February 5, 2011
  • 26. UNIFORM INTERFACE Self-Descriptive Messages [2] The Protocol Message • HTTP Header --> Content Negotiation • Contoh : Accept : application/xml • Status Respon : • Contoh : HTTP 1.1 / 200 OK ,HTTP 1.1 / 403 FORBIDDEN Saturday, February 5, 2011
  • 27. UNIFORM INTERFACE Self-Descriptive Messages [3] The Media Type • Struktur Dokumen Bisa Mudah Diolah • Contoh : • XML (application/xml) • Atom Pub (application/atom+xml) Saturday, February 5, 2011
  • 28. Contoh MediaType XML <messages> <message> <messageid>120</messageid> <author>Reza</author> <created>2011/02/04 08:20:12</created> <value>Hello, World!</value> <link>/message/120</link> <message> ........ ........ <messages> Saturday, February 5, 2011
  • 29. Contoh MediaType Atom <entry> <id>urn:uuid:95506d98-aae9-4d34-a8f4-1ff30bece80c</id> <title type=ʹ′ʹ′textʹ′ʹ′>product created</title> <updated>2009-07-05T10:25:00Z</updated> <link rel=ʹ′ʹ′selfʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/notifications/95506d98-aae9-4d34- a8f4-1ff30bece80cʹ′ʹ′/> <link rel=ʹ′ʹ′relatedʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/527ʹ′ʹ′/> <category scheme=ʹ′ʹ′http://starbucks.com/products/categories/typeʹ′ʹ′ term=ʹ′ʹ′productʹ′ʹ′/> <category scheme=ʹ′ʹ′http://starbucks.com/products/categories/statusʹ′ʹ′ term=ʹ′ʹ′newʹ′ʹ′/> <content type=ʹ′ʹ′application/vnd.starbucks+xmlʹ′ʹ′> <product xmlns=ʹ′ʹ′http://schemas.starbucks.com/productʹ′ʹ′ href=ʹ′ʹ′http://starbucks.com/products/527ʹ′ʹ′> <name>Fairtrade Roma Coffee Beans</name> <size>1kg</size> <price>10</price> <currency>$</currency> </product> </content> </entry> Saturday, February 5, 2011
  • 30. RESTLET FRAMEWORK Self-Descriptive Message [1] @Get("xml") public Representation get(){ String index = (String)getRequest().getAttributes().get("messageIndex"); StringRepresentation representation = null; String result = ""; try{ if(index != "" && index != null){ result = HelloBusiness.get(Integer.parseInt(index)); }else{ result = HelloBusiness.get(); } representation = new StringRepresentation (result, MediaType.APPLICATION_XML); return representation; }catch(NotFoundException e){ setStatus(Status.CLIENT_ERROR_NOT_FOUND); representation = new StringRepresentation ("no item found", MediaType.TEXT_PLAIN); return representation; } } Saturday, February 5, 2011
  • 31. RESTLET FRAMEWORK Self-Descriptive Message [2] <messages> <request>GET : ALL</request> <message> <request>GET</request> <value>Hello, World!</value> <link>/message/0</link> </message> <message> <request>GET</request> <value>Halo, Dunia!</value> <link>/message/1</link> </message> <message> <request>GET</request> <value>Apa Kabar?</value> <link>/message/2</link> </message> </messages> Saturday, February 5, 2011
  • 33. UNIFORM INTERFACE Hypermedia as The Engine of Application State (HATEOAS) [1] or Hypermedia constraints Saturday, February 5, 2011
  • 34. UNIFORM INTERFACE Hypermedia Constraint [1] • Inti dari Representational State Transfer • Menyatukan informasi proses bisnis dalam representasi resource Saturday, February 5, 2011
  • 35. UNIFORM INTERFACE Hypermedia Constraint [2] explains why named as “representational state transfer” Saturday, February 5, 2011
  • 36. UNIFORM INTERFACE Hypermedia Constraint [3] execution of business process “Consumers in a hypermedia system cause state transitions by visiting and manipulating resource state. Interestingly, the application state changes that result from a consumer driving a hypermedia system resemble the execution of a business process. This suggests that our services can advertise workflows using hypermedia.” - Jim Webber - REST In Practice Saturday, February 5, 2011
  • 37. UNIFORM INTERFACE Hypermedia Constraint [3] Best Practices • Menambahkan informasi possible next states langsung di dalam Representation • Caranya (untuk saat ini) : • possible next states ----> hyperlinks Saturday, February 5, 2011
  • 38. UNIFORM INTERFACE Hypermedia Constraint [4] examples <entry> <order xmlns=ʹ′ʹ′http://schemas.starbucks.comʹ′ʹ′> <location>takeAway</location> <item> <name>latte</name> <quantity>1</quantity> <milk>whole</milk> <size>small</size> </item> <cost>2.0</cost> <status>payment-expected</status> <link rel=ʹ′ʹ′http://relations.restbucks.com/paymentʹ′ʹ′ href=ʹ′ʹ′https://restbucks.com/payment/1234ʹ′ʹ′/> <link rel=ʹ′ʹ′http://relations.restbucks.com/special-offerʹ′ʹ′ href=ʹ′ʹ′http://restbucks.com/offers/cookie/1234ʹ′ʹ′/> </entry> Saturday, February 5, 2011
  • 39. UNIFORM INTERFACE Hypermedia Constraint [5] hypermedia support in MediaType • Lebih baik jangan gunakan MediaType XML untuk menambahkan hyperlinks di dalamnya. • Tidak ada dukungan langsung (native link tag) untuk hyperlinks • Gunakan Hypermedia Types (-Mike Amundsen) • Contoh : Atom • http://amundsen.com/hypermedia/ Saturday, February 5, 2011
  • 40. RESTLET FRAMEWORK Hypermedia Constraints [1] • Native support untuk mempermudah manajemen hypermedia constraints terdapat pada Restlet versi 2.1 (dalam pengembangan) • Solusi : Tambahkan secara manual ! :D • Solusi : Pakai versi 2.1 dengan resiko sendiri Saturday, February 5, 2011
  • 41. CONTOH APLIKASI LAIN SOCIAL COMMERCE [1] • Indeks Aplikasi Memuat : • Daftar Toko Online (dengan link masing-masing) • Link ke User Profile • Link ke Pengaturan Toko Online milik user Saturday, February 5, 2011
  • 42. CONTOH APLIKASI LAIN SOCIAL COMMERCE [2] • Masuk ke salah satu Toko Online (melalui link). Memuat : • Profil singkat penjual (dengan link ke profil lengkap) • Daftar Deskripsi Singkat Produk (dengan link masing- masing untuk deskripsi lengkap) • Link ke Indeks Saturday, February 5, 2011
  • 43. CONTOH APLIKASI LAIN SOCIAL COMMERCE [3] • Lihat deskripsi lengkap produk (melalui link). Memuat : • Informasi produk • Link untuk memesan • Link kembali ke Toko Online Saturday, February 5, 2011
  • 44. CONTOH APLIKASI LAIN SOCIAL COMMERCE [4] Saturday, February 5, 2011
  • 45. CONTOH APLIKASI LAIN SOCIAL COMMERCE [5] Saturday, February 5, 2011
  • 46. CONTOH APLIKASI LAIN SOCIAL COMMERCE [6] Saturday, February 5, 2011
  • 47. CONTOH APLIKASI LAIN SOCIAL COMMERCE [7] Saturday, February 5, 2011
  • 48. THANK YOU ! QUESTION? Saturday, February 5, 2011