51
RESTful Web Services in VA Smalltalk How to integrate your applications with today‘s technology trends Joachim Tuchel www.objektfabrik.de © 2009 by Joachim Tuchel

RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

RESTful Web Servicesin VA Smalltalk

How to integrate your applications

with today‘s technology trends

Joachim Tuchel

www.objektfabrik.de

© 2009 by Joachim Tuchel

Page 2: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Agenda

• About me and objektfabrik

• „Classic“ Web Services

• RESTful Web Services: What‘s different?

• RESTful Web Services with VA Smalltalk

• DEMO: REST Clients & Server

• Questions

Page 3: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

About me

• Founder and director of objektfabrik

• Business Informatics (Banking)

• Smalltalk since 1996(VA Smalltalk, VisualWorks and Squeak)

• Java since 2004

[email protected]

Page 4: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Some projects

• Fat Client and Web Applications in Smalltalk and Java

• Project Planning and Controlling

• Loan & Collateral Management

• Accounting for Small Businesses (Seaside)

• Migration of VA Smalltalk Projects to V6&7

Page 5: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

About objektfabrik

• Founded 1999 in Ludwigsburg, Germany

• Training, Consulting, Professional Services

• Application and System architecture

• Software Development in Smalltalk, Java, Ruby and Objective-C

• Instantiations Business Partner since 2006

Page 6: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Training offerings

• Object Technology Basics

• Smalltalk Basics

• VA Smalltalk Application Development

• Advanced VA Smalltalk workshops (Packaging, Config Management, SUnit...)

• New in 2009: Seaside

Page 7: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Web Servicesand VA Smalltalk

Page 8: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Web Services

• Uses HTTP/S POST for transport

• in theory uses any transport protocol

• XML Messages

• SOAP-Envelopes

• Namespaces

• Many standards / schemas available

Page 9: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Web Services

• W3C Standard

• Huge set of domain/industry specific and vertical (cross industry) standards (WS-*)

• Large selection of tools and vendors

• „Enterprise integration technology“

Page 10: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Web Services and VA Smalltalk

• Supported by VA Smalltalk since V 5.5

• Based on Server Smalltalk

• Constantly improved in 6.x, 7.x and 8

• Expose a Smalltalk method as a service

• Consume a service in Smalltalk

Page 11: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

What‘s wrong with Web Services

• Heavy weight standard

• One size fits all (by being large enough)

• Can be very complicated to deploy and debug

• Very complex XML structures

• Way too heavy for simple jobs

Page 12: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

RESTful Web Services

Page 13: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

RESTful Web Services

• REST = Representational State Transfer

• What is it?

• Not a standard

• It‘s an architecture

• Simplicity and Reuse of existing Standards like the HTTP (=Protocol) are design goals

Page 14: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

REST is everywhere

• Amazon Web Services

• Simple Storage System (S3)

• SimpleDB - SQL - like Database

• eBay Shopping APIs

• PayPal

Page 15: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

REST is everywhere

• Google REST APIs

• Search, Blogger, Maps, Analytics...

• Yahoo! REST APIs

• Finance, YQL, Travel, Weather...

• Twitter, Technorati, all over „Web 2.0“

• Apache CouchDB

Page 16: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

REST is everywhere

• REST is part of „The Web“ today

• REST is used for

• Integration

• Distribution

• Scaling

• Mashups

Page 17: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Page 18: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

• RESTful Web Services are about Resources, not about Services (operations)

Page 19: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

• RESTful Web Services are about Resources, not about Services (operations)

• Addressability: Every Resource has a uniform name = URI

Page 20: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

• RESTful Web Services are about Resources, not about Services (operations)

• Addressability: Every Resource has a uniform name = URI

http://myhost/users/joachim/todolists...

Page 21: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

• RESTful Web Services are about Resources, not about Services (operations)

• Addressability: Every Resource has a uniform name = URI

http://myhost/users/joachim/todolists...

• Statelessness: Server doesn‘t save any application state ➠ Scalability

Page 22: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

• Operations defined in HTTP standard

• Create: POST a new resource

• Read: GET a resource

• Update: PUT a resource

• Delete: DELETE a resource

• References to objects are IDs or hyperlinks

Page 23: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

What‘s a Resource?• Customer

• Purchasing Order

• Line Item

• Hotel Room

• Hotel Room Reservation

• User Account

• Database Transaction

• Flight Booking

• Message

• Dataset (RDB/OODB)

• any entity we deal with in our systems

Page 24: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

What‘s a Resource?

• Not necessarily a Business Object!

• Not all aspects need to be transported between applications

• Some aspects belong to a different Business Object (save bandwidth)

• References become IDs or Hyperlinks

Page 25: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Page 26: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Client

Page 27: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Client ResourceServer

Page 28: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Client ResourceServer

GET /users/Joachim

HTTP Request

Page 29: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Client ResourceServer

GET /users/Joachim

HTTP Request

HTTP Response

HTTP/1.1 200 OKContent-Type: application/xml<?xml version=...> <User firstname=“...

Page 30: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Basic Concepts

Client ResourceServer

GET /users/Joachim

HTTP Request

HTTP Response

HTTP/1.1 200 OKContent-Type: application/xml<?xml version=...> <User firstname=“...

Contents can beXML, JSON, CSV, Binary Data

...any MIME-Type

Page 31: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

HTTP and Response Codes: GET

• 200 OK

• 400 Bad Request

• 401 Unauthorized / 403 Forbidden

• 404 Not found

• 500 Internal Server Error

Page 32: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

HTTP Methods and Codes: POST

• 201 Created

• 409 Conflict

• 415 Unsupported Media Type

• 500 Internal Server Error

• Many more ...

Page 33: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Useful Advanced HTTP - Features

• If-Modified-Since / Last-Modified / 304 Not Modified for caching

• Cache-Control (read-only objects or infrequently changing objects)

• Content-Type to determine marshalers

• Accept-Ranges / Content-Range for partial loading of long lists etc.

Page 34: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Benefits of bare HTTP?

• Reduced Complexity: HTTP is easy

• Advantage in Development & Maintenance

• Uniform interface (HTTP) to every resource

• More flexibility: serving/accepting Resources instead of exposing a set of operations (➠Mashups)

Page 35: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

RESTful Web Services with VA Smalltalk

Page 36: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Ingredients for RESTful Web Services

• HTTP communications (Possibly HTTPS)

• Transport format for resource data

• XML, JSON, plain ascii

• Marshalling and unmarshalling on both ends

• Naming Service (URI ➠ Resource ➠ URI)

Page 37: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

VAST provides all the Building Blocks

• Server Smalltalk

• HTTP Client and Server

• Highly configurable and extendable on many levels

• Scalable (Multithreading by default)

• Mature (~10 years) and in use

• XML marshalling

Page 38: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Building a REST Client

• Extends SstHttpClient

• Adds xml marshalling (or other marshalling like)

• Wraps simple HTTP requests and handles response codes

• Optional: Session / cookie handling, caching ... (Maybe not „pure“ REST)

Page 39: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

PRESTON client

• getResourceNamed: aURI queryParameters: aDictionary

• postResource: anObject toResourceNamed: aURI

• deleteResourceNamed: aURI

• getOptionsForResourceNamed: aURI

• handles session cookies (optional)

Page 40: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

PRESTON client

• Mapping between Resource (e.g. XML) and Smalltalk objects

• Optional caching (URI → object)

• Proxies for hyperlinks (linked resource is only fetched if needed)

• Can act as database client to a RESTful web service

Page 41: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Demo:Yahoo! Traffic Client

Page 42: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Building a REST Server

• Extends several components of SST HTTP Server

• Is very similar to a servlet container (it serves resources with a certain URI)

• Adds marshalling, naming and more

Page 43: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

SST Building BlocksSstServerApplicationContext

containerKey

sessionManagerConfig.

attributes

initializeRequest:

handlesRequest:

SstBasicServer

applicationContexts

sessionManagers

startUp

shutDown

processClientRequest:

basicProcessRequest:

SstHttpServer

SstHttpServletEngine

SstHttpSessionManager

createSessionForRequest:

processRequest:

createCookieForSession:

cookieFromRequestHeader...

Page 44: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

SstServerApplicationContext

containerKey

sessionManagerConfig.

attributes

initializeRequest:

handlesRequest:

SstBasicServer

applicationContexts

sessionManagers

startUp

shutDown

processClientRequest:

basicProcessRequest:

SstHttpServer

SstHttpSessionManager

createSessionForRequest:

processRequest:

createCookieForSession:

cookieFromRequestHeader...

PrestonApplicationContext

resourceManagers

xmlMappingSpec

rootObject

PrestonServer

PrestonResourceManager

supportedHttpMethods

pathSegment

handleGETRequest..

handlePostRequest...

PRESTON Server

Page 45: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

• Yahoo! Traffic Client

• Yahoo! Traffic Client on a Seaside Server

• Todomatic Server & Client

Demos

Page 47: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

TodomaticRESTful Server

VA Smalltalk Image

HTTP Response

with optional

XML Document

HTTP Client* Web Browser* PRESTON Smalltalk client* Any other HTTP Client

GET users/joachim/todolistsPOST users/joachim/todolistsPUT users/joachim

eventually with

a message body

containing XML

document

User TodoList TodoItem

TodoLists andTodoItems

OODB

Page 48: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

Summary

Page 49: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

RESTful Web Services

• Anywhere on the web today and growing

• Far less complex than Web Services

• HTTP standard all the way down

• Can be used for Internet applications as well as for internal systems

• Integration

• Scaling

Page 50: RESTful Web Services in VA Smalltalk€¦ · Web Services and VA Smalltalk • Supported by VA Smalltalk since V 5.5 • Based on Server Smalltalk • Constantly improved in 6.x,

VA Smalltalk and RESTful Web Services• Most Web Services are CRUD operations

• Integration today mostly means combiningHTTP with XML or other text formats

• VA ST provides all the building blocks

• Some extensions needed

• Can be combined with Seaside easily

• Mashup your own services