Server push of responses
See original GitHub issueHTTP/2 RFC 7540 introduced the concept of server push. This allows a server to pre-emptively send (or “push”) responses to a client in association with a previous client-initiated request.
From an API perspective, it provides an interesting way of implementing the Observer pattern in which a client issues a request indicating interest in changes in an object’s state, and the notifications of the changes are delivered as pushed responses.
An alternative way of delivering notifications is proposed in #716, #735, #736 and #737. The callback/webhook pattern is widely used and would be a valuable addition to the specification.
Server push offers a method of delivering notifications from server to client in which the connection is initiated by the client. The client does not need to listen for connections from the server, and there is no need for the server to hold credentials for connecting to the client because it does not initiate connections.
A push
section is added to the operation object. This contains a list of possible push
responses. Upon receipt of a request for an operation, the server may push one or more
push responses prior to sending the final response for the operation.
An example below illustrates the concept.
paths:
/consumer:
post:
description: Create a consumer and start delivering messages
parameters:
- name: CreateConsumerRequest
in: body
required: true
schema:
$ref: '#/definitions/CreateConsumerRequest'
responses:
200:
description: Success
push:
/event:
responses:
200:
description: Event pushed to consumer
schema:
$ref: '#/defintions/Event'
headers:
offset:
description: Offset of this event
type: integer
definitions:
Event:
anyOf:
- $ref: '#/definitions/EventType1'
- $ref: '#/definitions/EventType2'
The push
object holds a list of Push Item Objects.
The Push Item Object contains a Push Path Object.
Field Pattern | Type | Description |
---|---|---|
/{path} | Push Path Object | A path for the pushed response. |
The Push Path Object describes the responses
.
Field Name | Type | Description |
---|---|---|
responses | Responses Object | Required. The list of possible responses. |
Pushed responses are just like regular responses of an operation.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:9 (4 by maintainers)
I would like to throw in gRPC that makes streaming (also bidirectional) first class definitions:
gRPC Concepts / RPC Lifecycle
This concept is very powerful and uses HTTP 2 to its full extend to get rid of all the hacks with long polling or all the complexities with context-loosing webhooks.
@AndrewJSchofield outside of HTTP/2 Server Push, there is also Server Sent Events.
This is similar to WebSockets, but works with a regular HTTP request, and is also possible to support resumption via the “ID” field.