PipelineClient Class
Service client core methods.
Builds a Pipeline client.
Constructor
PipelineClient(endpoint: str, *, pipeline: Pipeline[HTTPRequestType, HTTPResponseType] | None = None, **kwargs: Any)
Parameters
| Name | Description |
|---|---|
|
endpoint
Required
|
URL for the request. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
pipeline
|
<xref:<xref:corehttp.runtime.pipeline#corehttp.runtime.pipeline.Pipeline>>
If omitted, a Pipeline object is created. Default value: None
|
|
policies
|
If omitted, a set of standard policies is used. |
|
per_call_policies
|
If specified, the policies will be added into the policy list before RetryPolicy |
|
per_retry_policies
|
If specified, the policies will be added into the policy list after RetryPolicy |
|
transport
|
<xref:<xref:corehttp.transport#corehttp.transport.HttpTransport>>
If omitted, RequestsTransport is used for synchronous transport. |
Examples
Builds the pipeline client.
from corehttp.runtime import PipelineClient
from corehttp.rest import HttpRequest, HttpResponse
from corehttp.runtime.policies import (
HTTPPolicy,
SansIOHTTPPolicy,
HeadersPolicy,
UserAgentPolicy,
RetryPolicy,
)
policies: Iterable[Union[HTTPPolicy, SansIOHTTPPolicy]] = [
HeadersPolicy(),
UserAgentPolicy("myuseragent"),
RetryPolicy(),
]
client: PipelineClient[HttpRequest, HttpResponse] = PipelineClient("https://bing.com", policies=policies)
request = HttpRequest("GET", "https://bing.com")
response = client.send_request(request)
Variables
| Name | Description |
|---|---|
|
pipeline
|
<xref:<xref:corehttp.runtime.pipeline#corehttp.runtime.pipeline.Pipeline>> or
None
The Pipeline object associated with the client. |
Methods
| close | |
| format_url |
Format request URL with the client base URL, unless the supplied URL is already absolute. Note that both the base url and the template url can contain query parameters. |
| send_request |
Method that runs the network request through the client's chained policies.
|
close
close() -> None
format_url
Format request URL with the client base URL, unless the supplied URL is already absolute.
Note that both the base url and the template url can contain query parameters.
format_url(url_template: str, **kwargs: Any) -> str
Parameters
| Name | Description |
|---|---|
|
url_template
Required
|
The request URL to be formatted if necessary. |
Returns
| Type | Description |
|---|---|
|
The formatted URL. |
send_request
Method that runs the network request through the client's chained policies.
>>> from corehttp.rest import HttpRequest
>>> request = HttpRequest('GET', 'http://www.example.com')
<HttpRequest [GET], url: 'http://www.example.com'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>
send_request(request: HTTPRequestType, *, stream: bool = False, **kwargs: Any) -> HTTPResponseType
Parameters
| Name | Description |
|---|---|
|
request
Required
|
<xref:<xref:corehttp.rest#corehttp.rest.HttpRequest>>
The network request you want to make. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
stream
|
Whether the response payload will be streamed. Defaults to False. Default value: False
|
Returns
| Type | Description |
|---|---|
|
The response of your network call. Does not do error handling on your response. |