1package apimanagement
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"net/http"
26)
27
28// BackendClient is the apiManagement Client
29type BackendClient struct {
30	BaseClient
31}
32
33// NewBackendClient creates an instance of the BackendClient client.
34func NewBackendClient(subscriptionID string) BackendClient {
35	return NewBackendClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewBackendClientWithBaseURI creates an instance of the BackendClient client.
39func NewBackendClientWithBaseURI(baseURI string, subscriptionID string) BackendClient {
40	return BackendClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CreateOrUpdate creates or Updates a backend.
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// serviceName - the name of the API Management service.
47// backendid - identifier of the Backend entity. Must be unique in the current API Management service instance.
48// parameters - create parameters.
49func (client BackendClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendContract) (result BackendContract, err error) {
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: serviceName,
52			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
53				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
54				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
55		{TargetValue: backendid,
56			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
57				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
58				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
59		{TargetValue: parameters,
60			Constraints: []validation.Constraint{{Target: "parameters.BackendContractProperties", Name: validation.Null, Rule: false,
61				Chain: []validation.Constraint{{Target: "parameters.BackendContractProperties.URL", Name: validation.Null, Rule: true,
62					Chain: []validation.Constraint{{Target: "parameters.BackendContractProperties.URL", Name: validation.MaxLength, Rule: 2000, Chain: nil},
63						{Target: "parameters.BackendContractProperties.URL", Name: validation.MinLength, Rule: 1, Chain: nil},
64					}},
65				}}}}}); err != nil {
66		return result, validation.NewError("apimanagement.BackendClient", "CreateOrUpdate", err.Error())
67	}
68
69	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, backendid, parameters)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "CreateOrUpdate", nil, "Failure preparing request")
72		return
73	}
74
75	resp, err := client.CreateOrUpdateSender(req)
76	if err != nil {
77		result.Response = autorest.Response{Response: resp}
78		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "CreateOrUpdate", resp, "Failure sending request")
79		return
80	}
81
82	result, err = client.CreateOrUpdateResponder(resp)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "CreateOrUpdate", resp, "Failure responding to request")
85	}
86
87	return
88}
89
90// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
91func (client BackendClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendContract) (*http.Request, error) {
92	pathParameters := map[string]interface{}{
93		"backendid":         autorest.Encode("path", backendid),
94		"resourceGroupName": autorest.Encode("path", resourceGroupName),
95		"serviceName":       autorest.Encode("path", serviceName),
96		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
97	}
98
99	const APIVersion = "2017-03-01"
100	queryParameters := map[string]interface{}{
101		"api-version": APIVersion,
102	}
103
104	preparer := autorest.CreatePreparer(
105		autorest.AsContentType("application/json; charset=utf-8"),
106		autorest.AsPut(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
109		autorest.WithJSON(parameters),
110		autorest.WithQueryParameters(queryParameters))
111	return preparer.Prepare((&http.Request{}).WithContext(ctx))
112}
113
114// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
115// http.Response Body if it receives an error.
116func (client BackendClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
117	return autorest.SendWithSender(client, req,
118		azure.DoRetryWithRegistration(client.Client))
119}
120
121// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
122// closes the http.Response Body.
123func (client BackendClient) CreateOrUpdateResponder(resp *http.Response) (result BackendContract, err error) {
124	err = autorest.Respond(
125		resp,
126		client.ByInspecting(),
127		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
128		autorest.ByUnmarshallingJSON(&result),
129		autorest.ByClosing())
130	result.Response = autorest.Response{Response: resp}
131	return
132}
133
134// Delete deletes the specified backend.
135// Parameters:
136// resourceGroupName - the name of the resource group.
137// serviceName - the name of the API Management service.
138// backendid - identifier of the Backend entity. Must be unique in the current API Management service instance.
139// ifMatch - the entity state (Etag) version of the backend to delete. A value of "*" can be used for If-Match
140// to unconditionally apply the operation.
141func (client BackendClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, backendid string, ifMatch string) (result autorest.Response, err error) {
142	if err := validation.Validate([]validation.Validation{
143		{TargetValue: serviceName,
144			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
145				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
146				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
147		{TargetValue: backendid,
148			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
149				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
150				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
151		return result, validation.NewError("apimanagement.BackendClient", "Delete", err.Error())
152	}
153
154	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, backendid, ifMatch)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Delete", nil, "Failure preparing request")
157		return
158	}
159
160	resp, err := client.DeleteSender(req)
161	if err != nil {
162		result.Response = resp
163		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Delete", resp, "Failure sending request")
164		return
165	}
166
167	result, err = client.DeleteResponder(resp)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Delete", resp, "Failure responding to request")
170	}
171
172	return
173}
174
175// DeletePreparer prepares the Delete request.
176func (client BackendClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, ifMatch string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"backendid":         autorest.Encode("path", backendid),
179		"resourceGroupName": autorest.Encode("path", resourceGroupName),
180		"serviceName":       autorest.Encode("path", serviceName),
181		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
182	}
183
184	const APIVersion = "2017-03-01"
185	queryParameters := map[string]interface{}{
186		"api-version": APIVersion,
187	}
188
189	preparer := autorest.CreatePreparer(
190		autorest.AsDelete(),
191		autorest.WithBaseURL(client.BaseURI),
192		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
193		autorest.WithQueryParameters(queryParameters),
194		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
195	return preparer.Prepare((&http.Request{}).WithContext(ctx))
196}
197
198// DeleteSender sends the Delete request. The method will close the
199// http.Response Body if it receives an error.
200func (client BackendClient) DeleteSender(req *http.Request) (*http.Response, error) {
201	return autorest.SendWithSender(client, req,
202		azure.DoRetryWithRegistration(client.Client))
203}
204
205// DeleteResponder handles the response to the Delete request. The method always
206// closes the http.Response Body.
207func (client BackendClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
208	err = autorest.Respond(
209		resp,
210		client.ByInspecting(),
211		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
212		autorest.ByClosing())
213	result.Response = resp
214	return
215}
216
217// Get gets the details of the backend specified by its identifier.
218// Parameters:
219// resourceGroupName - the name of the resource group.
220// serviceName - the name of the API Management service.
221// backendid - identifier of the Backend entity. Must be unique in the current API Management service instance.
222func (client BackendClient) Get(ctx context.Context, resourceGroupName string, serviceName string, backendid string) (result BackendContract, err error) {
223	if err := validation.Validate([]validation.Validation{
224		{TargetValue: serviceName,
225			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
226				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
227				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
228		{TargetValue: backendid,
229			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
230				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
231				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
232		return result, validation.NewError("apimanagement.BackendClient", "Get", err.Error())
233	}
234
235	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, backendid)
236	if err != nil {
237		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Get", nil, "Failure preparing request")
238		return
239	}
240
241	resp, err := client.GetSender(req)
242	if err != nil {
243		result.Response = autorest.Response{Response: resp}
244		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Get", resp, "Failure sending request")
245		return
246	}
247
248	result, err = client.GetResponder(resp)
249	if err != nil {
250		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Get", resp, "Failure responding to request")
251	}
252
253	return
254}
255
256// GetPreparer prepares the Get request.
257func (client BackendClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string) (*http.Request, error) {
258	pathParameters := map[string]interface{}{
259		"backendid":         autorest.Encode("path", backendid),
260		"resourceGroupName": autorest.Encode("path", resourceGroupName),
261		"serviceName":       autorest.Encode("path", serviceName),
262		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
263	}
264
265	const APIVersion = "2017-03-01"
266	queryParameters := map[string]interface{}{
267		"api-version": APIVersion,
268	}
269
270	preparer := autorest.CreatePreparer(
271		autorest.AsGet(),
272		autorest.WithBaseURL(client.BaseURI),
273		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
274		autorest.WithQueryParameters(queryParameters))
275	return preparer.Prepare((&http.Request{}).WithContext(ctx))
276}
277
278// GetSender sends the Get request. The method will close the
279// http.Response Body if it receives an error.
280func (client BackendClient) GetSender(req *http.Request) (*http.Response, error) {
281	return autorest.SendWithSender(client, req,
282		azure.DoRetryWithRegistration(client.Client))
283}
284
285// GetResponder handles the response to the Get request. The method always
286// closes the http.Response Body.
287func (client BackendClient) GetResponder(resp *http.Response) (result BackendContract, err error) {
288	err = autorest.Respond(
289		resp,
290		client.ByInspecting(),
291		azure.WithErrorUnlessStatusCode(http.StatusOK),
292		autorest.ByUnmarshallingJSON(&result),
293		autorest.ByClosing())
294	result.Response = autorest.Response{Response: resp}
295	return
296}
297
298// GetEntityTag gets the entity state (Etag) version of the backend specified by its identifier.
299// Parameters:
300// resourceGroupName - the name of the resource group.
301// serviceName - the name of the API Management service.
302// backendid - identifier of the Backend entity. Must be unique in the current API Management service instance.
303func (client BackendClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string, backendid string) (result autorest.Response, err error) {
304	if err := validation.Validate([]validation.Validation{
305		{TargetValue: serviceName,
306			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
307				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
308				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
309		{TargetValue: backendid,
310			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
311				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
312				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
313		return result, validation.NewError("apimanagement.BackendClient", "GetEntityTag", err.Error())
314	}
315
316	req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName, backendid)
317	if err != nil {
318		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "GetEntityTag", nil, "Failure preparing request")
319		return
320	}
321
322	resp, err := client.GetEntityTagSender(req)
323	if err != nil {
324		result.Response = resp
325		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "GetEntityTag", resp, "Failure sending request")
326		return
327	}
328
329	result, err = client.GetEntityTagResponder(resp)
330	if err != nil {
331		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "GetEntityTag", resp, "Failure responding to request")
332	}
333
334	return
335}
336
337// GetEntityTagPreparer prepares the GetEntityTag request.
338func (client BackendClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string) (*http.Request, error) {
339	pathParameters := map[string]interface{}{
340		"backendid":         autorest.Encode("path", backendid),
341		"resourceGroupName": autorest.Encode("path", resourceGroupName),
342		"serviceName":       autorest.Encode("path", serviceName),
343		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
344	}
345
346	const APIVersion = "2017-03-01"
347	queryParameters := map[string]interface{}{
348		"api-version": APIVersion,
349	}
350
351	preparer := autorest.CreatePreparer(
352		autorest.AsHead(),
353		autorest.WithBaseURL(client.BaseURI),
354		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
355		autorest.WithQueryParameters(queryParameters))
356	return preparer.Prepare((&http.Request{}).WithContext(ctx))
357}
358
359// GetEntityTagSender sends the GetEntityTag request. The method will close the
360// http.Response Body if it receives an error.
361func (client BackendClient) GetEntityTagSender(req *http.Request) (*http.Response, error) {
362	return autorest.SendWithSender(client, req,
363		azure.DoRetryWithRegistration(client.Client))
364}
365
366// GetEntityTagResponder handles the response to the GetEntityTag request. The method always
367// closes the http.Response Body.
368func (client BackendClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) {
369	err = autorest.Respond(
370		resp,
371		client.ByInspecting(),
372		azure.WithErrorUnlessStatusCode(http.StatusOK),
373		autorest.ByClosing())
374	result.Response = resp
375	return
376}
377
378// ListByService lists a collection of backends in the specified service instance.
379// Parameters:
380// resourceGroupName - the name of the resource group.
381// serviceName - the name of the API Management service.
382// filter - | Field | Supported operators    | Supported functions                         |
383// |-------|------------------------|---------------------------------------------|
384// | id    | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
385// | host  | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
386// top - number of records to return.
387// skip - number of records to skip.
388func (client BackendClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result BackendCollectionPage, err error) {
389	if err := validation.Validate([]validation.Validation{
390		{TargetValue: serviceName,
391			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
392				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
393				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
394		{TargetValue: top,
395			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
396				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
397		{TargetValue: skip,
398			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
399				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
400		return result, validation.NewError("apimanagement.BackendClient", "ListByService", err.Error())
401	}
402
403	result.fn = client.listByServiceNextResults
404	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
405	if err != nil {
406		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "ListByService", nil, "Failure preparing request")
407		return
408	}
409
410	resp, err := client.ListByServiceSender(req)
411	if err != nil {
412		result.bc.Response = autorest.Response{Response: resp}
413		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "ListByService", resp, "Failure sending request")
414		return
415	}
416
417	result.bc, err = client.ListByServiceResponder(resp)
418	if err != nil {
419		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "ListByService", resp, "Failure responding to request")
420	}
421
422	return
423}
424
425// ListByServicePreparer prepares the ListByService request.
426func (client BackendClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
427	pathParameters := map[string]interface{}{
428		"resourceGroupName": autorest.Encode("path", resourceGroupName),
429		"serviceName":       autorest.Encode("path", serviceName),
430		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
431	}
432
433	const APIVersion = "2017-03-01"
434	queryParameters := map[string]interface{}{
435		"api-version": APIVersion,
436	}
437	if len(filter) > 0 {
438		queryParameters["$filter"] = autorest.Encode("query", filter)
439	}
440	if top != nil {
441		queryParameters["$top"] = autorest.Encode("query", *top)
442	}
443	if skip != nil {
444		queryParameters["$skip"] = autorest.Encode("query", *skip)
445	}
446
447	preparer := autorest.CreatePreparer(
448		autorest.AsGet(),
449		autorest.WithBaseURL(client.BaseURI),
450		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends", pathParameters),
451		autorest.WithQueryParameters(queryParameters))
452	return preparer.Prepare((&http.Request{}).WithContext(ctx))
453}
454
455// ListByServiceSender sends the ListByService request. The method will close the
456// http.Response Body if it receives an error.
457func (client BackendClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
458	return autorest.SendWithSender(client, req,
459		azure.DoRetryWithRegistration(client.Client))
460}
461
462// ListByServiceResponder handles the response to the ListByService request. The method always
463// closes the http.Response Body.
464func (client BackendClient) ListByServiceResponder(resp *http.Response) (result BackendCollection, err error) {
465	err = autorest.Respond(
466		resp,
467		client.ByInspecting(),
468		azure.WithErrorUnlessStatusCode(http.StatusOK),
469		autorest.ByUnmarshallingJSON(&result),
470		autorest.ByClosing())
471	result.Response = autorest.Response{Response: resp}
472	return
473}
474
475// listByServiceNextResults retrieves the next set of results, if any.
476func (client BackendClient) listByServiceNextResults(lastResults BackendCollection) (result BackendCollection, err error) {
477	req, err := lastResults.backendCollectionPreparer()
478	if err != nil {
479		return result, autorest.NewErrorWithError(err, "apimanagement.BackendClient", "listByServiceNextResults", nil, "Failure preparing next results request")
480	}
481	if req == nil {
482		return
483	}
484	resp, err := client.ListByServiceSender(req)
485	if err != nil {
486		result.Response = autorest.Response{Response: resp}
487		return result, autorest.NewErrorWithError(err, "apimanagement.BackendClient", "listByServiceNextResults", resp, "Failure sending next results request")
488	}
489	result, err = client.ListByServiceResponder(resp)
490	if err != nil {
491		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "listByServiceNextResults", resp, "Failure responding to next results request")
492	}
493	return
494}
495
496// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
497func (client BackendClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result BackendCollectionIterator, err error) {
498	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
499	return
500}
501
502// Reconnect notifies the APIM proxy to create a new connection to the backend after the specified timeout. If no
503// timeout was specified, timeout of 2 minutes is used.
504// Parameters:
505// resourceGroupName - the name of the resource group.
506// serviceName - the name of the API Management service.
507// backendid - identifier of the Backend entity. Must be unique in the current API Management service instance.
508// parameters - reconnect request parameters.
509func (client BackendClient) Reconnect(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters *BackendReconnectContract) (result autorest.Response, err error) {
510	if err := validation.Validate([]validation.Validation{
511		{TargetValue: serviceName,
512			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
513				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
514				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
515		{TargetValue: backendid,
516			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
517				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
518				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
519		{TargetValue: parameters,
520			Constraints: []validation.Constraint{{Target: "parameters", Name: validation.Null, Rule: false,
521				Chain: []validation.Constraint{{Target: "parameters.BackendReconnectProperties", Name: validation.Null, Rule: false,
522					Chain: []validation.Constraint{{Target: "parameters.BackendReconnectProperties.After", Name: validation.Null, Rule: false,
523						Chain: []validation.Constraint{{Target: "parameters.BackendReconnectProperties.After", Name: validation.MaxLength, Rule: 2000, Chain: nil},
524							{Target: "parameters.BackendReconnectProperties.After", Name: validation.MinLength, Rule: 1, Chain: nil},
525						}},
526					}},
527				}}}}}); err != nil {
528		return result, validation.NewError("apimanagement.BackendClient", "Reconnect", err.Error())
529	}
530
531	req, err := client.ReconnectPreparer(ctx, resourceGroupName, serviceName, backendid, parameters)
532	if err != nil {
533		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Reconnect", nil, "Failure preparing request")
534		return
535	}
536
537	resp, err := client.ReconnectSender(req)
538	if err != nil {
539		result.Response = resp
540		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Reconnect", resp, "Failure sending request")
541		return
542	}
543
544	result, err = client.ReconnectResponder(resp)
545	if err != nil {
546		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Reconnect", resp, "Failure responding to request")
547	}
548
549	return
550}
551
552// ReconnectPreparer prepares the Reconnect request.
553func (client BackendClient) ReconnectPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters *BackendReconnectContract) (*http.Request, error) {
554	pathParameters := map[string]interface{}{
555		"backendid":         autorest.Encode("path", backendid),
556		"resourceGroupName": autorest.Encode("path", resourceGroupName),
557		"serviceName":       autorest.Encode("path", serviceName),
558		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
559	}
560
561	const APIVersion = "2017-03-01"
562	queryParameters := map[string]interface{}{
563		"api-version": APIVersion,
564	}
565
566	preparer := autorest.CreatePreparer(
567		autorest.AsContentType("application/json; charset=utf-8"),
568		autorest.AsPost(),
569		autorest.WithBaseURL(client.BaseURI),
570		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}/reconnect", pathParameters),
571		autorest.WithQueryParameters(queryParameters))
572	if parameters != nil {
573		preparer = autorest.DecoratePreparer(preparer,
574			autorest.WithJSON(parameters))
575	}
576	return preparer.Prepare((&http.Request{}).WithContext(ctx))
577}
578
579// ReconnectSender sends the Reconnect request. The method will close the
580// http.Response Body if it receives an error.
581func (client BackendClient) ReconnectSender(req *http.Request) (*http.Response, error) {
582	return autorest.SendWithSender(client, req,
583		azure.DoRetryWithRegistration(client.Client))
584}
585
586// ReconnectResponder handles the response to the Reconnect request. The method always
587// closes the http.Response Body.
588func (client BackendClient) ReconnectResponder(resp *http.Response) (result autorest.Response, err error) {
589	err = autorest.Respond(
590		resp,
591		client.ByInspecting(),
592		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
593		autorest.ByClosing())
594	result.Response = resp
595	return
596}
597
598// Update updates an existing backend.
599// Parameters:
600// resourceGroupName - the name of the resource group.
601// serviceName - the name of the API Management service.
602// backendid - identifier of the Backend entity. Must be unique in the current API Management service instance.
603// parameters - update parameters.
604// ifMatch - the entity state (Etag) version of the backend to update. A value of "*" can be used for If-Match
605// to unconditionally apply the operation.
606func (client BackendClient) Update(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendUpdateParameters, ifMatch string) (result autorest.Response, err error) {
607	if err := validation.Validate([]validation.Validation{
608		{TargetValue: serviceName,
609			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
610				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
611				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
612		{TargetValue: backendid,
613			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
614				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
615				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
616		return result, validation.NewError("apimanagement.BackendClient", "Update", err.Error())
617	}
618
619	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, backendid, parameters, ifMatch)
620	if err != nil {
621		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Update", nil, "Failure preparing request")
622		return
623	}
624
625	resp, err := client.UpdateSender(req)
626	if err != nil {
627		result.Response = resp
628		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Update", resp, "Failure sending request")
629		return
630	}
631
632	result, err = client.UpdateResponder(resp)
633	if err != nil {
634		err = autorest.NewErrorWithError(err, "apimanagement.BackendClient", "Update", resp, "Failure responding to request")
635	}
636
637	return
638}
639
640// UpdatePreparer prepares the Update request.
641func (client BackendClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendUpdateParameters, ifMatch string) (*http.Request, error) {
642	pathParameters := map[string]interface{}{
643		"backendid":         autorest.Encode("path", backendid),
644		"resourceGroupName": autorest.Encode("path", resourceGroupName),
645		"serviceName":       autorest.Encode("path", serviceName),
646		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
647	}
648
649	const APIVersion = "2017-03-01"
650	queryParameters := map[string]interface{}{
651		"api-version": APIVersion,
652	}
653
654	preparer := autorest.CreatePreparer(
655		autorest.AsContentType("application/json; charset=utf-8"),
656		autorest.AsPatch(),
657		autorest.WithBaseURL(client.BaseURI),
658		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
659		autorest.WithJSON(parameters),
660		autorest.WithQueryParameters(queryParameters),
661		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
662	return preparer.Prepare((&http.Request{}).WithContext(ctx))
663}
664
665// UpdateSender sends the Update request. The method will close the
666// http.Response Body if it receives an error.
667func (client BackendClient) UpdateSender(req *http.Request) (*http.Response, error) {
668	return autorest.SendWithSender(client, req,
669		azure.DoRetryWithRegistration(client.Client))
670}
671
672// UpdateResponder handles the response to the Update request. The method always
673// closes the http.Response Body.
674func (client BackendClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
675	err = autorest.Respond(
676		resp,
677		client.ByInspecting(),
678		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
679		autorest.ByClosing())
680	result.Response = resp
681	return
682}
683