diff --git a/docs/migration-guide.asciidoc b/docs/migration-guide.asciidoc index 21f78589c1..1d3ae76032 100644 --- a/docs/migration-guide.asciidoc +++ b/docs/migration-guide.asciidoc @@ -292,13 +292,43 @@ As a last resort, the low-level client `Elastic.Transport` can be used to create [source,csharp] ---- +public class MyRequestParameters : RequestParameters +{ + public bool Pretty + { + get => Q("pretty"); + init => Q("pretty", value); + } +} + +// ... + var body = """ - { - "name": "my-api-key", - "expiration": "1d", - "...": "..." - } - """; - -var response = await client.Transport.RequestAsync(HttpMethod.POST, "/_security/api_key", PostData.String(body)); + { + "name": "my-api-key", + "expiration": "1d", + "...": "..." + } + """; + +MyRequestParameters requestParameters = new() +{ + Pretty = true +}; + +var pathAndQuery = requestParameters.CreatePathWithQueryStrings("/_security/api_key", + client.ElasticsearchClientSettings); +var endpointPath = new EndpointPath(Elastic.Transport.HttpMethod.POST, pathAndQuery); + +// Or, if the path does not contain query parameters: +// new EndpointPath(Elastic.Transport.HttpMethod.POST, "my_path") + +var response = await client.Transport + .RequestAsync( + endpointPath, + PostData.String(body), + null, + null, + cancellationToken: default) + .ConfigureAwait(false); ---- \ No newline at end of file diff --git a/docs/usage/index.asciidoc b/docs/usage/index.asciidoc index c6ae095064..87edb3f8d3 100644 --- a/docs/usage/index.asciidoc +++ b/docs/usage/index.asciidoc @@ -14,9 +14,10 @@ If you're new to {es}, make sure also to read {ref}/getting-started.html[Elastic NOTE: This is still a work in progress, more sections will be added in the near future. -include::recommendations.asciidoc[] +include::aggregations.asciidoc[] +include::esql.asciidoc[] include::examples.asciidoc[] -include::query.asciidoc[] include::mappings.asciidoc[] -include::aggregations.asciidoc[] -include::esql.asciidoc[] \ No newline at end of file +include::query.asciidoc[] +include::recommendations.asciidoc[] +include::transport.asciidoc[] diff --git a/docs/usage/transport.asciidoc b/docs/usage/transport.asciidoc new file mode 100644 index 0000000000..3e15fbd0b9 --- /dev/null +++ b/docs/usage/transport.asciidoc @@ -0,0 +1,47 @@ +[[transport]] +== Transport example + +This page demonstrates how to use the low level transport to send requests. + +[source,csharp] +---- +public class MyRequestParameters : RequestParameters +{ + public bool Pretty + { + get => Q("pretty"); + init => Q("pretty", value); + } +} + +// ... + +var body = """ + { + "name": "my-api-key", + "expiration": "1d", + "...": "..." + } + """; + +MyRequestParameters requestParameters = new() +{ + Pretty = true +}; + +var pathAndQuery = requestParameters.CreatePathWithQueryStrings("/_security/api_key", + client.ElasticsearchClientSettings); +var endpointPath = new EndpointPath(Elastic.Transport.HttpMethod.POST, pathAndQuery); + +// Or, if the path does not contain query parameters: +// new EndpointPath(Elastic.Transport.HttpMethod.POST, "my_path") + +var response = await client.Transport + .RequestAsync( + endpointPath, + PostData.String(body), + null, + null, + cancellationToken: default) + .ConfigureAwait(false); +----