RESTful Webservice
RESTful Webservice
Materi
Pengenalan Webservice
RESTful Webservice
Implementasi RESTful Webservice
Pengenalan Webservice
web browser
Webserver
Masalah 1
Bagaimana jika yang berkomunikasi adalah dua entitas
mesin yang berbeda tanpa campur tangan manusia ?
Misal : SI Penggajian memerlukan data pegawai dari SI
Kepegawaian
Webserver
SI Penggajian
Webserver
SI Kepegawaian
Masalah 2
Bagaimana caranya agar aplikasi native (mobile,
desktop) bisa bertukar data dengan webserver yang
berbeda bahasa pemrograman ?
Misal : Aplikasi mobile (Java) mengakses data pengguna dari
web application (PHP)
Mobile Android
Webserver
Webservice
Web service adalah metode komunikasi
machine-to-machine lewat protokol web (http)
Mekanisme request-response sama dengan web page
biasa
Hanya berbeda pada representasi response data
Tidak ada interpretasi manual oleh manusia
Web Service
Mesin
Format dan Struktur Data
Bebas
Contoh Kasus
Contoh Kasus
Housingmaps.com is a mashup created of
Craigslist
Arsitektur Webservice
Terdapat beberapa jenis arsitektur
webservice
RESTful Webservice
RESTful Webservice
Representational State Transfer (REST)
Resource based webservice
Conceptual Overview
REST Architectural Constrains (1)
Client-server
Separation of concerns
Clients are separated from servers by a uniform interface.
Networking
Clients are not concerned with data storage, which remains internal
to each server, so that the portability of client code is improved.
Servers are not concerned with the user interface or user state, so
that servers can be simpler and more scalable.
Independent evolution
Servers and clients may also be replaced and developed
independently, as long as the interface is not altered.
Conceptual Overview
REST Architectural Constrains (2)
Stateless communication
Scalability, reliability
No client context being stored on the server between requests. Each request
from any client contains all of the information necessary to service the request.
Uniform Interface
Simplicity (vs. efficiency)
Large-grained hypermedia data transfer
Example: Create, Retrieve, Update, Delete
Conceptual Overview
REST Architectural Constrains (3)
Caching
Efficiency, scalability
Well-managed caching partially or completely eliminates some client-server
interactions, further improving scalability and performance.
Consistency issues
As on the World Wide Web, clients are able to cache responses. Responses must
therefore, implicitly or explicitly, define themselves as cacheable or not, to
prevent clients reusing stale or inappropriate data in response to further
requests.
Code-on-demand
Extending client functionality
Servers are able to temporarily extend or customize the functionality of a client
by transferring to it logic that it can execute. Examples of this may include
compiled components such as Java applets and client-side scripts such as
JavaScript.
REST Client
PHP : curl
Python : urllib2, urllib, drest
Java : HttpURLConnection+JSON Parser,
Retrofit
Contoh Kasus
Contoh Kasus
Akses data Pegawai dengan RESTful
webservice
Server = Flask
Python Django bisa diganti PHP,
Codeigniter,dll.
Data Pegawai disimpan dalam sebuah
list/array
Client Server
Demo
Tugas
Buatlah sistem manajemen penggajian sederhanya
berbasis RESTful webservice dengan ketentuan :
Data Pegawai meliput nama, alamat disimpan di Server 1
Data Gaji Pegawai disimpan di Server 2
Operasi pada data Pegawai dan Gajinya meliputi : create, read,
update, delete
Client hanya perlu terhubung ke Server 1 untuk melakukan
operasi data
Data Pegawai dan Gajinya disimpan dalam sebuah database
SQLite
Terima Kasih