Take a small REST Simple approaches for REST in smalltalk Norbert - - PowerPoint PPT Presentation

take a small rest
SMART_READER_LITE
LIVE PREVIEW

Take a small REST Simple approaches for REST in smalltalk Norbert - - PowerPoint PPT Presentation

Take a small REST Simple approaches for REST in smalltalk Norbert Hartl 2denker What we do... ...at 2denker mobile applications backend services for mobile applications backend services for b2b Why REST? there are RPC-style services (SOAP


slide-1
SLIDE 1

Take a small REST

Simple approaches for REST in smalltalk Norbert Hartl 2denker

slide-2
SLIDE 2

What we do...

...at 2denker mobile applications backend services for mobile applications backend services for b2b

slide-3
SLIDE 3

Why REST?

there are RPC-style services (SOAP , XML-RPC,...)

slide-4
SLIDE 4

Why REST?

there are RPC-style services (SOAP , XML-RPC,...) REST is data-centric

slide-5
SLIDE 5

Why REST?

there are RPC-style services (SOAP , XML-RPC,...) REST is data-centric REST/HTTP has meta data

slide-6
SLIDE 6

Why REST?

there are RPC-style services (SOAP , XML-RPC,...) REST is data-centric REST/HTTP has meta data REST is about identity

slide-7
SLIDE 7

Smalltalk tools to do REST

Magritte Magritte-XMLBinding Magritte-JSON Seaside-REST

slide-8
SLIDE 8

serialization/materialization

using magritte meta tool support model with meta information validation of model using meta information conversion into/from formats with meta info

slide-9
SLIDE 9

Example class Person

fullName emailAddress

slide-10
SLIDE 10

model with meta information

Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

slide-11
SLIDE 11

model with meta information

(using pragma to add a description)

Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

slide-12
SLIDE 12

model with meta information

(adding type information)

Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

slide-13
SLIDE 13

model with meta information

(specifying value store/retrieve operation)

Person>>#fullNameDescription <magritteDescription> ^ MAStringDescription new accessor: #fullName; label: 'full name'; beRequired; priority: 100; yourself

slide-14
SLIDE 14

validation using meta info

(magritte)

Person>>#emailAddressDescription <magritteDescription> ^ MAStringDescription new accessor: #emailAddress; label: 'email address'; addCondition: [:val| val includes: $@ ] labelled: 'address must contain @'; beRequired; priority: 200; yourself

slide-15
SLIDE 15

validation using meta info

(magritte)

Person>>#emailAddressDescription <magritteDescription> ^ MAStringDescription new accessor: #emailAddress; label: 'email address'; addCondition: [:val| val includes: $@ ] labelled: 'address must contain @'; beRequired; priority: 200; yourself

slide-16
SLIDE 16

validation using meta info

(magritte)

Person>>#emailAddressDescription <magritteDescription> ^ MAStringDescription new accessor: #emailAddress; label: 'email address'; addCondition: [:val| val includes: $@ ] labelled: 'address must contain @'; beRequired; priority: 200; yourself

slide-17
SLIDE 17

adding conversion info

(for Magritte-XMLBinding)

fullNameXmlDescription: aDescription <magritteDescription: #fullNameDescription> ^ aDescription xmlElementName: 'fullname' emailAddressXmlDescription: aDescription <magritteDescription: #emailAddressDescription> ^ aDescription xmlAttributeName: 'email'

slide-18
SLIDE 18

conversion into/from format

p := Person new. p fullName: 'John Doe'; emailAddress: 'john@doe.it'. p magritteDescription toXml: p

<Person email="john@doe.it"> <fullname>John Doe</fullname> </Person>

slide-19
SLIDE 19

REST call flow

message routing and parameter handling content type selection serializiation/materialization to/from network data

slide-20
SLIDE 20

message routing

time <get> <path: '/time'> self requestContext response status: 200; nextPutAll: Time now greaseString; respond

slide-21
SLIDE 21

message routing

(matching HTTP verb)

time <get> <path: '/time'> self requestContext response status: 200; nextPutAll: Time now greaseString; respond

slide-22
SLIDE 22

message routing

(matching path/parameters)

time <get> <path: '/time'> self requestContext response status: 200; nextPutAll: Time now greaseString; respond

slide-23
SLIDE 23

content type xml

getPersonXml: aString <get> <path: '/person/{1}'> <produces: 'application/xml'> self requestContext response status: 200; nextPutAll: ( self description toXml: (self personWithId: aString)); respond

slide-24
SLIDE 24

content type xml

(placeholder in url become method paramter)

getPersonXml: aString <get> <path: '/person/{1}'> <produces: 'application/xml'> self requestContext response status: 200; nextPutAll: ( self description toXml: (self personWithId: aString)); respond

slide-25
SLIDE 25

content type xml

(content type selection based on Accept header)

getPersonXml: aString <get> <path: '/person/{1}'> <produces: 'application/xml'> self requestContext response status: 200; nextPutAll: ( self description toXml: (self personWithId: aString)); respond

slide-26
SLIDE 26

content type json

getPersonJson: aString <get> <path: '/person/{1}'> <produces: 'application/json'> self requestContext response status: 200; nextPutAll: (String streamContents: [:stream| (self personWithId: aString) jsonOn: stream]); respond

slide-27
SLIDE 27

example post

addPersonFromJson <post> <path: '/person'> <consumes: 'application/json'> self addPersonUsing: [ self materializeFromJson ]

slide-28
SLIDE 28

example post

(content type selection based on Content-Type header)

addPersonFromJson <post> <path: '/person'> <consumes: 'application/json'> self addPersonUsing: [ self materializeFromJson ]

slide-29
SLIDE 29

Demo

slide-30
SLIDE 30

Thank you! Questions?