Skip to content

migrate SDKs to use HTTP pipeline #802

Closed
@cataggar

Description

@cataggar

An HTTP pipeline general guidelines:
https://azure.github.io/azure-sdk/general_azurecore.html

A description copied from #290:


Previous to the pipeline architecture, each operation was independently controlled meaning there was no central way to control the way operations were performed.

The pipeline architecture on the other hand allows users of the SDK to create pipelines through which outgoing requests and incoming responses are processed. The pipeline are composed of "policies" which can both change the outgoing request and the incoming response. Policies are usually either on a "per-request" basis (meaning they are called only once per operation) or "per-retry" (meaning they are applied every time an operation is attempted).

Examples of policies are the TelemetryPolicy which adds various telemetry headers to the request and the retry policy which checks whether an incoming response was successful and if it detects a transient failure, retries the request.

Converting to the Architecture

For an example of converting one operation (Cosmos's get_database operation) over to the pipeline architecture, take a look at #286.

The basic steps are:

  • Create a new submodule of the operations module where the operation will live. This submodule should be named after the operation (e.g., for get_database it's called get_database).
  • Move the "request builder" (e.g., for get_database the GetDatabaseBuilder) to new operation submodule and rename it from Builder to Options (e.g., GetDatabaseBuilder => GetDatabaseOptions`). This now represents the options that can be supplied when performing the operation. Note that many options that were part of the builder are no longer valid options because there will be individual policies that take their place. For instance, previously many operations took an option to set the user agent. This is now done by a policy.
  • Change the execute method to a decorate_request method that instead of performing the request, simply mutates a request parameter with any of the options supplied.
  • Move the associated response type (e.g., for get_database the GetDatabaseResponse type from the responses submodule to the operation submodule. Previously a std::convert::TryFrom implementation was used to convert from an http::Response<Bytes> object. This should now be a plain associated async function called try_from that converts from the new Response type. See the example for how this should be done.
  • Finally, convert the appropriate method on the appropriate client (e.g., for get_database this was the DatabaseClient::get_database) to use the new options and response types with the pipeline. Again, see the example for how this should be done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions