SlideShare ist ein Scribd-Unternehmen logo
1 von 37
REST 
DESIGN 
LAB 
PROGRAMAÇÃO DE SISTEMAS 
DISTRIBUÍDOS 
Paulo Gandra de Sousa 
pag@isep.ipp.pt
Lab #2 
Retail
System architecture 
For argument 
sake let’s 
ignore 
payments
Use case: Process a customer 
order * 
1. Find the nearest warehouse to the customer 
2. if warehouse has enough inventory of the 
product 
1. Reserve the product at the warehouse 
2. Obtain a quote from each dispatcher 
3. Order the dispatching service to wining bid 
4. Confirm reservation at warehouse 
3. Repeat 1-2 for “next” nearest warehouse until 
all itens are satisfied 
* (advanced) order may be split in several packages from 
different warehouses.
Tips 
 Don’t think about the user interface but instead 
think about “atomic” business operation 
requests 
 Authentication is outside of the application 
protocol 
 Decide on a base format, e.g., XML, JSON, 
HTML 
 Whenever possible use standard media types, 
e.g., vCard 
 Most resources will follow a collection/item 
pattern
Tips 
 Remember, each service is autonomous, 
 just because some resource has the same name 
it doesn’t mean it is the same kind of resource 
and has the same representations 
 Services don’t know and don’t have access to the 
internals of other services, e.g., database 
 Don’t expose implementation details 
 Don’t forget hypermedia
A solution 
This is one possible solution, based on lots 
of implicit assumptions and on the author’s 
personal opinions!
Main Services/Resources 
 Retail 
 Order 
 User 
 Geo 
 Distance 
 Warehouse 
 Order 
 Product 
 Dispatcher 
 Order 
 User 
 Supplier 
 Product 
 Order 
 User
Retail service 
Resource Description 
Order The collection of user orders 
POST – submit a new order 
Order/:id A specific user order 
GET – get the order details 
PUT – update the order 
DELETE – cancel the order 
Order/:id/shipping The shipping address of a specific order 
GET – get the shipping address 
PUT – change the order’s shipping address 
Order/:id/itens The ordered itens 
GET – get the ordered itens details 
POST – add a new item to the order 
Order/:id/itens/:idx A specific ordered item 
GET – get the order line details 
PUT – update the order line, e.g., quantity 
DELETE – remove the item from the order
Retail service (cont.d) 
Resource Description 
Product GET The product catalog (filtered, paged) 
Product/:id A specific product sold at the retail site 
GET – get the product details 
User The collection of registered users of the retail service 
POST – register a new user 
User/:uid A specific registered user 
GET – get the user details 
PUT – update the user details 
DELETE – remove account 
User/:uid/Address The collection of known addresses of a user 
GET, PUT, DELETE 
User/:uid/Address/:ai 
d 
A specific user address 
GET, PUT, DELETE 
User/:uid/orders GET The collection of orders from a specific user 
(filtered)
Submit a new order (request) 
POST /order 
{ customer: CUSTOMER-URI, 
itens: [ { product: PRODUCT-URI, 
quantity: NUMBER, 
}, 
... 
], 
paymentAuth: OBJECT, 
billingAddress: CUST-ADDR-URI, 
shippingAddress: CUST-ADDR-URI, 
shippingMode: STRING, 
}
Submit a new order (response) 
201 Created 
Location: http://myretail.com/order/123 
{ id: http://myretail.com/order/123 //ORDER-URI, 
customer: CUSTOMER-URI, 
packages: [ { itens: [ { product: PRODUCT-URI, 
quantity: NUMBER, 
}, ... ], 
expectDeliveryOn: DATE, 
}, ... ] 
paymentAuth: OBJECT, 
billingAddress: CUST-ADDR-URI, 
shippingAddress: CUST-ADDR-URI, 
shippingMode: STRING, 
cost: { amount: NUMBER, currency: STRING } 
status: STRING, 
acceptedOn: DATE, 
} 
Basic hypermedia 
for now
Order media type 
 shippingMode can have one of the following 
values “regular”, “express”, “overnight” 
 status can have one of the following values 
“pending”, “processing”, “transiting”, 
“delivered”, “fulfilled” 
 currency is an ISO 4217 code, e.g., EUR
Obtain a user’s list of orders 
GET /user/:uid/orders 
 Query parameters: 
 status – the status to filter, e.g., “pending”, 
“processing”, “transiting”, “delivered”, “fulfilled” 
 from - the starting date in YYYY-MM-DD format 
 to - the end date in YYYY-MM-DD format
Obtain a user’s list of orders 
(response) 
200 Ok 
Location: http://myretail.com/user/123/orders 
{ orders: [ ORDER-URI, ... ], 
filters: { status: STRING, 
from: DATE, 
to: DATE 
} 
} 
Returning just the 
index of orders but 
could return the 
complete order 
objects 
The active filters used 
for the GET. This might 
be duplicated 
information in the 
request.
GeoService 
 Location 
 GET 
 DistanceCalculator 
 POST 
 Typically we would 
use an existing geo 
service such as 
Bing, Google or 
Yahoo and not 
define our own 
service
Calculate distance (request) 
POST /DistanceCalculator 
{ from: { type: STRING, 
LOCATION 
}, 
to: { ... }, 
options: [ OPTION ], 
}
Calculate distance 
 type indicates the kind of location info. 
Currently it can have the values “LatLong” and 
“address” 
 LOCATION if type = LatLong 
 {lat: STRING, log: STRING} 
 LOCATION if type = address 
 {country: STRING, address: STRING} 
 OPTION can have the values “fastest”, “eco”, 
“no-toll”
Warehouse service 
Resource Description 
Location GET The location of the warehouse 
Order The collection of warehouse orders 
POST 
Order/:id A specific warehouse order 
GET – get the order details 
PUT – update the entire order 
POST – confirms the reservation 
DELETE – cancel the order 
Order/:id/itens The ordered itens 
GET – get the ordered itens details 
POST – add a new item to the order 
Order/:id/itens/:idx A specific ordered item 
GET – get the order line details 
PUT – update the order line, e.g., quantity 
DELETE – remove the item from the order 
Product GET The product catalog 
Product/:id GET A specific product “available” at the warehouse 
Product/:id/inventory GET The current inventory of a product
Place an order (request) 
POST /order 
{ customerOrder: CUSTOMER-ORDER-URI, 
itens: [ { product: PRODUCT-URI, 
quantity: NUMBER, 
}, 
... 
], 
}
Place an order (response) 
201 Created 
Location: http://mywarehouse-1.com/order/123 
{ id: http://mywarehouse-1.com/order/123 , //ORDER-URI 
customerOrder: CUSTOMER-ORDER-URI, 
itens: [ { product: PRODUCT-URI, 
quantity: NUMBER, 
}, 
... 
], 
status: “reserved”, 
reservationExpiresOn: DATE, 
acceptedOn: DATE, 
expectReadyBy: DATE 
} 
This is not a 
Customer Order!! 
Basic hypermedia 
for now
Warehouse Order media type 
 status can have one of the following values 
“reserved”, “confirmed”, “processing”, 
“processed”, “picked-up” 
 The order is always created as a reservation with 
a time limit
No inventory 
409 Conflict 
{ reason: STRING, 
inventory: [ { product: PRODUCT-URI, 
stock: NUMBER, 
}, 
... 
], 
}
Confirm the reservation 
(request) 
POST /order/1234 
{ status: “confirmed” 
} Check HTTP 
PATCH
Confirm the reservation 
(response) 
200 Ok 
{ id: http://mywarehouse-1.com/order/123 , //ORDER-URI 
customerOrder: CUSTOMER-ORDER-URI, 
itens: [ { product: PRODUCT-URI, 
quantity: NUMBER, 
}, 
... 
], 
status: STRING, 
acceptedOn: DATE, 
expectReadyBy: DATE 
} 
reservationExpires 
is no longer part of 
the representation
Reservation expired 
410 Gone
Dispatcher service 
 Order 
 POST 
 Order/:id 
 GET 
 POST 
 PUT 
 DELETE 
 User/:id 
 GET 
 PUT
Block execution until dispatcher sends the 
quotation? 
Definitely Not. 
Retail service should provide a callback for 
assynchronous communication. Or should poll 
the quote resource.
Non blocking communication 
Callback Polling
Ask for a quotation (request) 
POST /quote 
{ myRef: CUSTOMER-ORDER-URI, 
pickup: ADDRESS, 
delivery: ADDRESS, 
volumes : [ {weight: NUMBER, 
height: NUMBER, 
width: NUMBER, 
depth: NUMBER}], 
serviceType: STRING, 
callback: URI, 
}
Ask for a quotation (response) 
202 Accepted
Place a bid (request) 
POST /order/:id/quote/:id 
{ id: http://dispatcher-1.com/quote/123 , //QUOTE-URI 
yourRef: CUSTOMER-ORDER-URI, 
itens: [ { product: PRODUCT-URI, 
quantity: NUMBER, 
}, 
... 
], 
cost: {amount: NUMBER, currency: STRING}, 
expiresOn: DATE, 
expectedPickup: DATE, 
expectedDelivery: DATE, 
}
Place a bid (response) 
200 Ok 
OR 
204 No Content
Place an order based on a quote 
(request) 
POST /order 
{ quote: QUOTE-URI, 
packages: [STRING, …], 
pickup-contact : {name: STRING, 
phone: STRING, 
email: STRING}, 
delivery-contact : {name: STRING, 
phone: STRING, 
email: STRING}, 
}
Place an order based on a quote 
(response) 
201 Created 
Location: http://dispatcher-1.com/order/765 
{ id: http://dispatcher-1.com/order/765 , //ORDER-URI 
yourRef: CUSTOMER-ORDER-URI, 
quote: QUOTE-URI 
packages: ... 
status: STRING, 
acceptedOn: DATE, 
cost: {amount: NUMBER, currency: STRING}, 
expectedPickup: DATE, 
expectedDelivery: DATE, 
}
Quote expired 
410 Gone
Supplier 
 Order 
 POST 
 Order/:id 
 GET 
 POST 
 PUT 
 DELETE 
 Product 
 GET 
 Product/:id 
 GET 
 User/:id 
 GET 
 PUT

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (7)

Principles of Service Orientation
Principles of Service OrientationPrinciples of Service Orientation
Principles of Service Orientation
 
Lição prova professor coordenador
Lição prova professor coordenadorLição prova professor coordenador
Lição prova professor coordenador
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Patterns for distributed systems
Patterns for distributed systemsPatterns for distributed systems
Patterns for distributed systems
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
 

Ähnlich wie RESTful services Design Lab

Mongo db ecommerce
Mongo db ecommerceMongo db ecommerce
Mongo db ecommercechristkv
 
Building RESTful API
Building RESTful APIBuilding RESTful API
Building RESTful APIAnna Pietras
 
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed InventoryRetail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed InventoryMongoDB
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigDusan Zamurovic
 
Gharpay rest documentation
Gharpay rest documentationGharpay rest documentation
Gharpay rest documentationDebjeet Biswas
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Abstracting functionality with centralised content
Abstracting functionality with centralised contentAbstracting functionality with centralised content
Abstracting functionality with centralised contentMichael Peacock
 
How to convert custom plsql to web services-Soap OR Rest
How to convert custom plsql to web services-Soap OR RestHow to convert custom plsql to web services-Soap OR Rest
How to convert custom plsql to web services-Soap OR Restshravan kumar chelika
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMongoDB
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMongoDB
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web servicesmwinteringham
 
Refactoring domain driven design way
Refactoring domain driven design wayRefactoring domain driven design way
Refactoring domain driven design wayAndi Pangeran
 
Kotlin coroutines 톺아보기
Kotlin coroutines 톺아보기Kotlin coroutines 톺아보기
Kotlin coroutines 톺아보기Taewoo Kim
 

Ähnlich wie RESTful services Design Lab (20)

Consumer-Centric API Design
Consumer-Centric API DesignConsumer-Centric API Design
Consumer-Centric API Design
 
Mongo db ecommerce
Mongo db ecommerceMongo db ecommerce
Mongo db ecommerce
 
Consumer-centric API Design
Consumer-centric API DesignConsumer-centric API Design
Consumer-centric API Design
 
Building RESTful API
Building RESTful APIBuilding RESTful API
Building RESTful API
 
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed InventoryRetail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
Retail Reference Architecture Part 2: Real-Time, Geo Distributed Inventory
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPig
 
Gharpay rest documentation
Gharpay rest documentationGharpay rest documentation
Gharpay rest documentation
 
ALC Presentation_012915
ALC Presentation_012915ALC Presentation_012915
ALC Presentation_012915
 
Finishing School .Net Work-Shop (Day2)
Finishing School .Net Work-Shop (Day2)Finishing School .Net Work-Shop (Day2)
Finishing School .Net Work-Shop (Day2)
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
E-Bazaar
E-BazaarE-Bazaar
E-Bazaar
 
Abstracting functionality with centralised content
Abstracting functionality with centralised contentAbstracting functionality with centralised content
Abstracting functionality with centralised content
 
How to convert custom plsql to web services-Soap OR Rest
How to convert custom plsql to web services-Soap OR RestHow to convert custom plsql to web services-Soap OR Rest
How to convert custom plsql to web services-Soap OR Rest
 
Tradecloud REST API intro for Buyers
Tradecloud REST API intro for BuyersTradecloud REST API intro for Buyers
Tradecloud REST API intro for Buyers
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodb
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
 
Refactoring domain driven design way
Refactoring domain driven design wayRefactoring domain driven design way
Refactoring domain driven design way
 
Kotlin coroutines 톺아보기
Kotlin coroutines 톺아보기Kotlin coroutines 톺아보기
Kotlin coroutines 톺아보기
 

Mehr von Paulo Gandra de Sousa (9)

Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Minds-on DDD
Minds-on DDDMinds-on DDD
Minds-on DDD
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
 
Hypermedia APIs
Hypermedia APIsHypermedia APIs
Hypermedia APIs
 
Revision control with Mercurial
Revision control with MercurialRevision control with Mercurial
Revision control with Mercurial
 
Documenting Software Architectures
Documenting Software ArchitecturesDocumenting Software Architectures
Documenting Software Architectures
 
models of distributed computing
models of distributed computingmodels of distributed computing
models of distributed computing
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 

Kürzlich hochgeladen

FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Kürzlich hochgeladen (20)

FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 

RESTful services Design Lab

  • 1. REST DESIGN LAB PROGRAMAÇÃO DE SISTEMAS DISTRIBUÍDOS Paulo Gandra de Sousa pag@isep.ipp.pt
  • 3. System architecture For argument sake let’s ignore payments
  • 4. Use case: Process a customer order * 1. Find the nearest warehouse to the customer 2. if warehouse has enough inventory of the product 1. Reserve the product at the warehouse 2. Obtain a quote from each dispatcher 3. Order the dispatching service to wining bid 4. Confirm reservation at warehouse 3. Repeat 1-2 for “next” nearest warehouse until all itens are satisfied * (advanced) order may be split in several packages from different warehouses.
  • 5. Tips  Don’t think about the user interface but instead think about “atomic” business operation requests  Authentication is outside of the application protocol  Decide on a base format, e.g., XML, JSON, HTML  Whenever possible use standard media types, e.g., vCard  Most resources will follow a collection/item pattern
  • 6. Tips  Remember, each service is autonomous,  just because some resource has the same name it doesn’t mean it is the same kind of resource and has the same representations  Services don’t know and don’t have access to the internals of other services, e.g., database  Don’t expose implementation details  Don’t forget hypermedia
  • 7. A solution This is one possible solution, based on lots of implicit assumptions and on the author’s personal opinions!
  • 8. Main Services/Resources  Retail  Order  User  Geo  Distance  Warehouse  Order  Product  Dispatcher  Order  User  Supplier  Product  Order  User
  • 9. Retail service Resource Description Order The collection of user orders POST – submit a new order Order/:id A specific user order GET – get the order details PUT – update the order DELETE – cancel the order Order/:id/shipping The shipping address of a specific order GET – get the shipping address PUT – change the order’s shipping address Order/:id/itens The ordered itens GET – get the ordered itens details POST – add a new item to the order Order/:id/itens/:idx A specific ordered item GET – get the order line details PUT – update the order line, e.g., quantity DELETE – remove the item from the order
  • 10. Retail service (cont.d) Resource Description Product GET The product catalog (filtered, paged) Product/:id A specific product sold at the retail site GET – get the product details User The collection of registered users of the retail service POST – register a new user User/:uid A specific registered user GET – get the user details PUT – update the user details DELETE – remove account User/:uid/Address The collection of known addresses of a user GET, PUT, DELETE User/:uid/Address/:ai d A specific user address GET, PUT, DELETE User/:uid/orders GET The collection of orders from a specific user (filtered)
  • 11. Submit a new order (request) POST /order { customer: CUSTOMER-URI, itens: [ { product: PRODUCT-URI, quantity: NUMBER, }, ... ], paymentAuth: OBJECT, billingAddress: CUST-ADDR-URI, shippingAddress: CUST-ADDR-URI, shippingMode: STRING, }
  • 12. Submit a new order (response) 201 Created Location: http://myretail.com/order/123 { id: http://myretail.com/order/123 //ORDER-URI, customer: CUSTOMER-URI, packages: [ { itens: [ { product: PRODUCT-URI, quantity: NUMBER, }, ... ], expectDeliveryOn: DATE, }, ... ] paymentAuth: OBJECT, billingAddress: CUST-ADDR-URI, shippingAddress: CUST-ADDR-URI, shippingMode: STRING, cost: { amount: NUMBER, currency: STRING } status: STRING, acceptedOn: DATE, } Basic hypermedia for now
  • 13. Order media type  shippingMode can have one of the following values “regular”, “express”, “overnight”  status can have one of the following values “pending”, “processing”, “transiting”, “delivered”, “fulfilled”  currency is an ISO 4217 code, e.g., EUR
  • 14. Obtain a user’s list of orders GET /user/:uid/orders  Query parameters:  status – the status to filter, e.g., “pending”, “processing”, “transiting”, “delivered”, “fulfilled”  from - the starting date in YYYY-MM-DD format  to - the end date in YYYY-MM-DD format
  • 15. Obtain a user’s list of orders (response) 200 Ok Location: http://myretail.com/user/123/orders { orders: [ ORDER-URI, ... ], filters: { status: STRING, from: DATE, to: DATE } } Returning just the index of orders but could return the complete order objects The active filters used for the GET. This might be duplicated information in the request.
  • 16. GeoService  Location  GET  DistanceCalculator  POST  Typically we would use an existing geo service such as Bing, Google or Yahoo and not define our own service
  • 17. Calculate distance (request) POST /DistanceCalculator { from: { type: STRING, LOCATION }, to: { ... }, options: [ OPTION ], }
  • 18. Calculate distance  type indicates the kind of location info. Currently it can have the values “LatLong” and “address”  LOCATION if type = LatLong  {lat: STRING, log: STRING}  LOCATION if type = address  {country: STRING, address: STRING}  OPTION can have the values “fastest”, “eco”, “no-toll”
  • 19. Warehouse service Resource Description Location GET The location of the warehouse Order The collection of warehouse orders POST Order/:id A specific warehouse order GET – get the order details PUT – update the entire order POST – confirms the reservation DELETE – cancel the order Order/:id/itens The ordered itens GET – get the ordered itens details POST – add a new item to the order Order/:id/itens/:idx A specific ordered item GET – get the order line details PUT – update the order line, e.g., quantity DELETE – remove the item from the order Product GET The product catalog Product/:id GET A specific product “available” at the warehouse Product/:id/inventory GET The current inventory of a product
  • 20. Place an order (request) POST /order { customerOrder: CUSTOMER-ORDER-URI, itens: [ { product: PRODUCT-URI, quantity: NUMBER, }, ... ], }
  • 21. Place an order (response) 201 Created Location: http://mywarehouse-1.com/order/123 { id: http://mywarehouse-1.com/order/123 , //ORDER-URI customerOrder: CUSTOMER-ORDER-URI, itens: [ { product: PRODUCT-URI, quantity: NUMBER, }, ... ], status: “reserved”, reservationExpiresOn: DATE, acceptedOn: DATE, expectReadyBy: DATE } This is not a Customer Order!! Basic hypermedia for now
  • 22. Warehouse Order media type  status can have one of the following values “reserved”, “confirmed”, “processing”, “processed”, “picked-up”  The order is always created as a reservation with a time limit
  • 23. No inventory 409 Conflict { reason: STRING, inventory: [ { product: PRODUCT-URI, stock: NUMBER, }, ... ], }
  • 24. Confirm the reservation (request) POST /order/1234 { status: “confirmed” } Check HTTP PATCH
  • 25. Confirm the reservation (response) 200 Ok { id: http://mywarehouse-1.com/order/123 , //ORDER-URI customerOrder: CUSTOMER-ORDER-URI, itens: [ { product: PRODUCT-URI, quantity: NUMBER, }, ... ], status: STRING, acceptedOn: DATE, expectReadyBy: DATE } reservationExpires is no longer part of the representation
  • 27. Dispatcher service  Order  POST  Order/:id  GET  POST  PUT  DELETE  User/:id  GET  PUT
  • 28. Block execution until dispatcher sends the quotation? Definitely Not. Retail service should provide a callback for assynchronous communication. Or should poll the quote resource.
  • 29. Non blocking communication Callback Polling
  • 30. Ask for a quotation (request) POST /quote { myRef: CUSTOMER-ORDER-URI, pickup: ADDRESS, delivery: ADDRESS, volumes : [ {weight: NUMBER, height: NUMBER, width: NUMBER, depth: NUMBER}], serviceType: STRING, callback: URI, }
  • 31. Ask for a quotation (response) 202 Accepted
  • 32. Place a bid (request) POST /order/:id/quote/:id { id: http://dispatcher-1.com/quote/123 , //QUOTE-URI yourRef: CUSTOMER-ORDER-URI, itens: [ { product: PRODUCT-URI, quantity: NUMBER, }, ... ], cost: {amount: NUMBER, currency: STRING}, expiresOn: DATE, expectedPickup: DATE, expectedDelivery: DATE, }
  • 33. Place a bid (response) 200 Ok OR 204 No Content
  • 34. Place an order based on a quote (request) POST /order { quote: QUOTE-URI, packages: [STRING, …], pickup-contact : {name: STRING, phone: STRING, email: STRING}, delivery-contact : {name: STRING, phone: STRING, email: STRING}, }
  • 35. Place an order based on a quote (response) 201 Created Location: http://dispatcher-1.com/order/765 { id: http://dispatcher-1.com/order/765 , //ORDER-URI yourRef: CUSTOMER-ORDER-URI, quote: QUOTE-URI packages: ... status: STRING, acceptedOn: DATE, cost: {amount: NUMBER, currency: STRING}, expectedPickup: DATE, expectedDelivery: DATE, }
  • 37. Supplier  Order  POST  Order/:id  GET  POST  PUT  DELETE  Product  GET  Product/:id  GET  User/:id  GET  PUT

Hinweis der Redaktion

  1. Warehouses are dynamic but well known Geolocation is wellknown Dispatcher and supliers are dynamic and must bu queried thru directory
  2. Eventough there is the need from the back-office perspective to manage all the orders, it doesn’t make sense to expose the entire collection of orders thru the API. There is a separate acess mechanism for back-office applications. Of course it could be exposed here and rely on authorizations to distinguish who can do what. Instead of allowing POST on a specific order to change it we use “subresources” for the common update operations, i.e., changeShippingAddress, cancelOrder, addItem, removeItem, changeQuantity
  3. Eventough warehouses do not change locations often this is a good candidate to be part of the resource info and be cached for long time. Of course since this is a piece of well known information it could be easily part of the Retail internal database The Product catalog lists all the products thta this warehouse usually has, but has no garantee that ther eis enough inventory at this moment. Since getting the inventory level might a constly operation we separate it in a different resource from the catalog itself.
  4. The customer order is passed as a reference for further interactions from the Reatil service but the warehouse has no access to the order itself, so the Retail must pass the itens it wants to order. In some situations the Reatil might decid to order some itens of the same customer order to warehouse A and others to warehouse B
  5. There is no need to place the cost of the order as that is retail information and not warehouse. There could be however na “internal” cost to be charged to the retail service
  6. Returns the inventory at hand of the requested products that cannot bu fulfilled. That is, if the client ordered 10 units of product A and 5 units of product B and the warehouse has enough of product A but only 1 unit of product B it will reply with na array with one member stating that product B has not enough inventory.
  7. There is no need to place the cost of the order as that is retial information and not arehouse. There could be however na “internal” cost to be charged to the retail service
  8. Customer neste caso é o cliente da trasnprotadora, ou seja o Retial e não o cliente final serviceId é o código da encomenda no armazém e não o código do serviço da transportadora – esse é retornado porteriormente
  9. Note that usually you wouldn’t define the API of na external provider unless you are a business giant and can impose your rule son the market. For this exercise we will assume that scenario. The customer order is passed as a reference for further interactions from the Reatil service but the Dispatcher has no access to the order itself.
  10. Note that usually you wouldn’t define the API of na external provider unless you are a business giant and can impose your rule son the market. For this exercise we will assume that scenario. The customer order is passed as a reference for further interactions from the Reatil service but the Dispatcher has no access to the order itself.
  11. The Dispatcher will call back at the specified URI. In this case we have used a URI for each quote request we did for each order but remeber that URI are opaque to the client so the dispatcher has no idea of the meaning of the URI
  12. This is just the Retail saying “I received your quote and will look into it”