essential api facade patterns: synchronous to asynchronous conversion (episode 4)

Post on 26-May-2015

4.148 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Apigee@apigee

Santanu Dey@Santanu_Dey

Essential API Facade Patterns

Episode 4 – Synchronous to Asynchronous Conversion

groups.google.com/group/api-craft

slideshare.net/apigee

youtube.com/apigee

@Santanu_DeySantanu Dey

Episode 1Composition

Episode 2Session Management

Episode 3One Phase to Two Phase Conversion

Episode 4Synchronous to Asynchronous Conversion

Webcast Series: API Facade Patterns

Problem

Solution

Benefits

Considerations

Episode 4 : Synchronous to Asynchronous ConversionConversion

Conversion of asynchronous style APIs to synchronous

To enable API teams and app developers to implement and improve their API designs and apps

Problem

Example of a Synchronous API

Client waitsfor the response

API Provider

1. Request

2. Response

Example of a Synchronous API

POST http://example.com/smsmessaging/outbound/tel%3A%2B12345678/requests

{"outboundSMSMessageRequest":{ "address":["tel:+13500000991”],

"senderAddress":"tel:12345678", "outboundSMSTextMessage":

{"message":"Hello World”},

"senderName":"ACME Inc.”}

}

Example of a Synchronous API

Response:

HTTP/1.1 200

{"deliveryInfo": {

"address":"tel:+1350000991", "deliveryStatus":"DeliveredToNetwork”

}}

}

What are the Constructs of an Asynchronous API?

Example of an Asynchronous API

Client does not wait for the completion of the process

API Provider

1. RequestClient

Example of an Asynchronous API

Client does not wait for the completion of the process

API Provider

1. Request

Server calls back

2. Asynch Response

Client

Example of an Asynchronous API

POST http://example.com/smsmessaging/outbound/tel%3A%2B12345678/requests{"outboundSMSMessageRequest":

{ "address":["tel:+13500000991”],

"senderAddress":"tel:12345678", "outboundSMSTextMessage":

{"message":"Hello World”},

"senderName":"ACME Inc.”}"receiptRequest": {

"notifyURL":"http://…/notifications/", "callbackData":”12345"},

}

Example of an Asynchronous API

Immediate Response:

HTTP/1.1 201

{"deliveryInfo": {

"address":"tel:+1350000991", "deliveryStatus":"MessageWaiting”

}}

"receiptRequest": {

"notifyURL":"http://…/notifications/", "callbackData":”12345"},

}

Example of an Asynchronous API

Asynch Call-back Response (A new request):

POST http://Client-app.example.com/notifications/{"deliveryInfoNotification": {

"callbackData": "12345”,"deliveryInfo":

{ "address":"tel:+1350000991", "deliveryStatus":"DeliveredToNetwork"

}}}

The end-user facing application use-case may require synchronous behavior

Having a call back URL from a client-application is not feasible

Solution

The solution is to introduce an API Façade in the middle which can handle the conversion

Synch to Asynch

Asynch. ProviderAsynch Synch

Warning! UML Ahead

When the Target Does not Provide a Call Back

Client does not wait for the completion of the process API

Provider

1. Request

Client checks for the status later

2. Check Status

Example of the API Façade

Backend Server

API Façade

Existing Capabilities

API Exposure &

Mgmt.

App relies on REST

Benefits

The API Façade provides a secure & reliable call back host

Robust callback processing options in the API Façade

This pattern can be applied to mediate REST APIs to asynchronous messaging transports such as JMS

Other Considerations

What is a good timeout for asynch to synch conversion?

Do not abandon the Asynchronous APIs• High throughput• Lower response-time

If you really need a synch API -

Have a synchronous variation of the same API alongside an asynchronous variation

Provide Choice to Developers when Possible

Questions?

THANK YOUSubscribe to API webcasts at:

youtube.com/apigee

Apigee@apigee

THANK YOUQuestions and ideas to:

groups.google.com/group/api-craft

Apigee@apigee

THANK YOUContact me at:

@Santanu_Deysdey@apigee.com

Apigee@apigee

top related