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	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// BackendsClient is the apiManagement Client
30type BackendsClient struct {
31	BaseClient
32}
33
34// NewBackendsClient creates an instance of the BackendsClient client.
35func NewBackendsClient(subscriptionID string) BackendsClient {
36	return NewBackendsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewBackendsClientWithBaseURI creates an instance of the BackendsClient client.
40func NewBackendsClientWithBaseURI(baseURI string, subscriptionID string) BackendsClient {
41	return BackendsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate creates or Updates a backend.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// serviceName - the name of the API Management service.
48// backendid - user identifier. Must be unique in the current API Management service instance.
49// parameters - create parameters.
50func (client BackendsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendContract) (result autorest.Response, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/BackendsClient.CreateOrUpdate")
53		defer func() {
54			sc := -1
55			if result.Response != nil {
56				sc = result.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: serviceName,
63			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
64				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
65				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
66		{TargetValue: backendid,
67			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
68				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}},
70		{TargetValue: parameters,
71			Constraints: []validation.Constraint{{Target: "parameters.Host", Name: validation.Null, Rule: true,
72				Chain: []validation.Constraint{{Target: "parameters.Host", Name: validation.MaxLength, Rule: 255, Chain: nil},
73					{Target: "parameters.Host", Name: validation.MinLength, Rule: 1, Chain: nil},
74				}}}}}); err != nil {
75		return result, validation.NewError("apimanagement.BackendsClient", "CreateOrUpdate", err.Error())
76	}
77
78	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, backendid, parameters)
79	if err != nil {
80		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "CreateOrUpdate", nil, "Failure preparing request")
81		return
82	}
83
84	resp, err := client.CreateOrUpdateSender(req)
85	if err != nil {
86		result.Response = resp
87		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "CreateOrUpdate", resp, "Failure sending request")
88		return
89	}
90
91	result, err = client.CreateOrUpdateResponder(resp)
92	if err != nil {
93		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "CreateOrUpdate", resp, "Failure responding to request")
94	}
95
96	return
97}
98
99// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
100func (client BackendsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendContract) (*http.Request, error) {
101	pathParameters := map[string]interface{}{
102		"backendid":         autorest.Encode("path", backendid),
103		"resourceGroupName": autorest.Encode("path", resourceGroupName),
104		"serviceName":       autorest.Encode("path", serviceName),
105		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
106	}
107
108	const APIVersion = "2016-07-07"
109	queryParameters := map[string]interface{}{
110		"api-version": APIVersion,
111	}
112
113	preparer := autorest.CreatePreparer(
114		autorest.AsContentType("application/json; charset=utf-8"),
115		autorest.AsPut(),
116		autorest.WithBaseURL(client.BaseURI),
117		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
118		autorest.WithJSON(parameters),
119		autorest.WithQueryParameters(queryParameters))
120	return preparer.Prepare((&http.Request{}).WithContext(ctx))
121}
122
123// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
124// http.Response Body if it receives an error.
125func (client BackendsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
126	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
127	return autorest.SendWithSender(client, req, sd...)
128}
129
130// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
131// closes the http.Response Body.
132func (client BackendsClient) CreateOrUpdateResponder(resp *http.Response) (result autorest.Response, err error) {
133	err = autorest.Respond(
134		resp,
135		client.ByInspecting(),
136		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusNoContent),
137		autorest.ByClosing())
138	result.Response = resp
139	return
140}
141
142// Delete deletes the specified backend.
143// Parameters:
144// resourceGroupName - the name of the resource group.
145// serviceName - the name of the API Management service.
146// backendid - user identifier. Must be unique in the current API Management service instance.
147// ifMatch - the entity state (Etag) version of the backend to delete. A value of "*" can be used for If-Match
148// to unconditionally apply the operation.
149func (client BackendsClient) Delete(ctx context.Context, resourceGroupName string, serviceName string, backendid string, ifMatch string) (result autorest.Response, err error) {
150	if tracing.IsEnabled() {
151		ctx = tracing.StartSpan(ctx, fqdn+"/BackendsClient.Delete")
152		defer func() {
153			sc := -1
154			if result.Response != nil {
155				sc = result.Response.StatusCode
156			}
157			tracing.EndSpan(ctx, sc, err)
158		}()
159	}
160	if err := validation.Validate([]validation.Validation{
161		{TargetValue: serviceName,
162			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
163				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
164				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
165		{TargetValue: backendid,
166			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
167				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
168				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
169		return result, validation.NewError("apimanagement.BackendsClient", "Delete", err.Error())
170	}
171
172	req, err := client.DeletePreparer(ctx, resourceGroupName, serviceName, backendid, ifMatch)
173	if err != nil {
174		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Delete", nil, "Failure preparing request")
175		return
176	}
177
178	resp, err := client.DeleteSender(req)
179	if err != nil {
180		result.Response = resp
181		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Delete", resp, "Failure sending request")
182		return
183	}
184
185	result, err = client.DeleteResponder(resp)
186	if err != nil {
187		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Delete", resp, "Failure responding to request")
188	}
189
190	return
191}
192
193// DeletePreparer prepares the Delete request.
194func (client BackendsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, ifMatch string) (*http.Request, error) {
195	pathParameters := map[string]interface{}{
196		"backendid":         autorest.Encode("path", backendid),
197		"resourceGroupName": autorest.Encode("path", resourceGroupName),
198		"serviceName":       autorest.Encode("path", serviceName),
199		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
200	}
201
202	const APIVersion = "2016-07-07"
203	queryParameters := map[string]interface{}{
204		"api-version": APIVersion,
205	}
206
207	preparer := autorest.CreatePreparer(
208		autorest.AsDelete(),
209		autorest.WithBaseURL(client.BaseURI),
210		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
211		autorest.WithQueryParameters(queryParameters),
212		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
213	return preparer.Prepare((&http.Request{}).WithContext(ctx))
214}
215
216// DeleteSender sends the Delete request. The method will close the
217// http.Response Body if it receives an error.
218func (client BackendsClient) DeleteSender(req *http.Request) (*http.Response, error) {
219	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
220	return autorest.SendWithSender(client, req, sd...)
221}
222
223// DeleteResponder handles the response to the Delete request. The method always
224// closes the http.Response Body.
225func (client BackendsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
226	err = autorest.Respond(
227		resp,
228		client.ByInspecting(),
229		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
230		autorest.ByClosing())
231	result.Response = resp
232	return
233}
234
235// Get gets the details of the backend specified by its identifier.
236// Parameters:
237// resourceGroupName - the name of the resource group.
238// serviceName - the name of the API Management service.
239// backendid - user identifier. Must be unique in the current API Management service instance.
240func (client BackendsClient) Get(ctx context.Context, resourceGroupName string, serviceName string, backendid string) (result BackendResponse, err error) {
241	if tracing.IsEnabled() {
242		ctx = tracing.StartSpan(ctx, fqdn+"/BackendsClient.Get")
243		defer func() {
244			sc := -1
245			if result.Response.Response != nil {
246				sc = result.Response.Response.StatusCode
247			}
248			tracing.EndSpan(ctx, sc, err)
249		}()
250	}
251	if err := validation.Validate([]validation.Validation{
252		{TargetValue: serviceName,
253			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
254				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
255				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
256		{TargetValue: backendid,
257			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
258				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
259				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
260		return result, validation.NewError("apimanagement.BackendsClient", "Get", err.Error())
261	}
262
263	req, err := client.GetPreparer(ctx, resourceGroupName, serviceName, backendid)
264	if err != nil {
265		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Get", nil, "Failure preparing request")
266		return
267	}
268
269	resp, err := client.GetSender(req)
270	if err != nil {
271		result.Response = autorest.Response{Response: resp}
272		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Get", resp, "Failure sending request")
273		return
274	}
275
276	result, err = client.GetResponder(resp)
277	if err != nil {
278		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Get", resp, "Failure responding to request")
279	}
280
281	return
282}
283
284// GetPreparer prepares the Get request.
285func (client BackendsClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string) (*http.Request, error) {
286	pathParameters := map[string]interface{}{
287		"backendid":         autorest.Encode("path", backendid),
288		"resourceGroupName": autorest.Encode("path", resourceGroupName),
289		"serviceName":       autorest.Encode("path", serviceName),
290		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
291	}
292
293	const APIVersion = "2016-07-07"
294	queryParameters := map[string]interface{}{
295		"api-version": APIVersion,
296	}
297
298	preparer := autorest.CreatePreparer(
299		autorest.AsGet(),
300		autorest.WithBaseURL(client.BaseURI),
301		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
302		autorest.WithQueryParameters(queryParameters))
303	return preparer.Prepare((&http.Request{}).WithContext(ctx))
304}
305
306// GetSender sends the Get request. The method will close the
307// http.Response Body if it receives an error.
308func (client BackendsClient) GetSender(req *http.Request) (*http.Response, error) {
309	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
310	return autorest.SendWithSender(client, req, sd...)
311}
312
313// GetResponder handles the response to the Get request. The method always
314// closes the http.Response Body.
315func (client BackendsClient) GetResponder(resp *http.Response) (result BackendResponse, err error) {
316	err = autorest.Respond(
317		resp,
318		client.ByInspecting(),
319		azure.WithErrorUnlessStatusCode(http.StatusOK),
320		autorest.ByUnmarshallingJSON(&result),
321		autorest.ByClosing())
322	result.Response = autorest.Response{Response: resp}
323	return
324}
325
326// ListByService lists a collection of backends in the specified service instance.
327// Parameters:
328// resourceGroupName - the name of the resource group.
329// serviceName - the name of the API Management service.
330// filter - | Field | Supported operators    | Supported functions                         |
331// |-------|------------------------|---------------------------------------------|
332// | id    | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
333// | host  | ge, le, eq, ne, gt, lt | substringof, contains, startswith, endswith |
334// top - number of records to return.
335// skip - number of records to skip.
336func (client BackendsClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result BackendCollectionPage, err error) {
337	if tracing.IsEnabled() {
338		ctx = tracing.StartSpan(ctx, fqdn+"/BackendsClient.ListByService")
339		defer func() {
340			sc := -1
341			if result.bc.Response.Response != nil {
342				sc = result.bc.Response.Response.StatusCode
343			}
344			tracing.EndSpan(ctx, sc, err)
345		}()
346	}
347	if err := validation.Validate([]validation.Validation{
348		{TargetValue: serviceName,
349			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
350				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
351				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
352		{TargetValue: top,
353			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
354				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}}}}},
355		{TargetValue: skip,
356			Constraints: []validation.Constraint{{Target: "skip", Name: validation.Null, Rule: false,
357				Chain: []validation.Constraint{{Target: "skip", Name: validation.InclusiveMinimum, Rule: 0, Chain: nil}}}}}}); err != nil {
358		return result, validation.NewError("apimanagement.BackendsClient", "ListByService", err.Error())
359	}
360
361	result.fn = client.listByServiceNextResults
362	req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName, filter, top, skip)
363	if err != nil {
364		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "ListByService", nil, "Failure preparing request")
365		return
366	}
367
368	resp, err := client.ListByServiceSender(req)
369	if err != nil {
370		result.bc.Response = autorest.Response{Response: resp}
371		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "ListByService", resp, "Failure sending request")
372		return
373	}
374
375	result.bc, err = client.ListByServiceResponder(resp)
376	if err != nil {
377		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "ListByService", resp, "Failure responding to request")
378	}
379
380	return
381}
382
383// ListByServicePreparer prepares the ListByService request.
384func (client BackendsClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (*http.Request, error) {
385	pathParameters := map[string]interface{}{
386		"resourceGroupName": autorest.Encode("path", resourceGroupName),
387		"serviceName":       autorest.Encode("path", serviceName),
388		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
389	}
390
391	const APIVersion = "2016-07-07"
392	queryParameters := map[string]interface{}{
393		"api-version": APIVersion,
394	}
395	if len(filter) > 0 {
396		queryParameters["$filter"] = autorest.Encode("query", filter)
397	}
398	if top != nil {
399		queryParameters["$top"] = autorest.Encode("query", *top)
400	}
401	if skip != nil {
402		queryParameters["$skip"] = autorest.Encode("query", *skip)
403	}
404
405	preparer := autorest.CreatePreparer(
406		autorest.AsGet(),
407		autorest.WithBaseURL(client.BaseURI),
408		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends", pathParameters),
409		autorest.WithQueryParameters(queryParameters))
410	return preparer.Prepare((&http.Request{}).WithContext(ctx))
411}
412
413// ListByServiceSender sends the ListByService request. The method will close the
414// http.Response Body if it receives an error.
415func (client BackendsClient) ListByServiceSender(req *http.Request) (*http.Response, error) {
416	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
417	return autorest.SendWithSender(client, req, sd...)
418}
419
420// ListByServiceResponder handles the response to the ListByService request. The method always
421// closes the http.Response Body.
422func (client BackendsClient) ListByServiceResponder(resp *http.Response) (result BackendCollection, err error) {
423	err = autorest.Respond(
424		resp,
425		client.ByInspecting(),
426		azure.WithErrorUnlessStatusCode(http.StatusOK),
427		autorest.ByUnmarshallingJSON(&result),
428		autorest.ByClosing())
429	result.Response = autorest.Response{Response: resp}
430	return
431}
432
433// listByServiceNextResults retrieves the next set of results, if any.
434func (client BackendsClient) listByServiceNextResults(ctx context.Context, lastResults BackendCollection) (result BackendCollection, err error) {
435	req, err := lastResults.backendCollectionPreparer(ctx)
436	if err != nil {
437		return result, autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "listByServiceNextResults", nil, "Failure preparing next results request")
438	}
439	if req == nil {
440		return
441	}
442	resp, err := client.ListByServiceSender(req)
443	if err != nil {
444		result.Response = autorest.Response{Response: resp}
445		return result, autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "listByServiceNextResults", resp, "Failure sending next results request")
446	}
447	result, err = client.ListByServiceResponder(resp)
448	if err != nil {
449		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "listByServiceNextResults", resp, "Failure responding to next results request")
450	}
451	return
452}
453
454// ListByServiceComplete enumerates all values, automatically crossing page boundaries as required.
455func (client BackendsClient) ListByServiceComplete(ctx context.Context, resourceGroupName string, serviceName string, filter string, top *int32, skip *int32) (result BackendCollectionIterator, err error) {
456	if tracing.IsEnabled() {
457		ctx = tracing.StartSpan(ctx, fqdn+"/BackendsClient.ListByService")
458		defer func() {
459			sc := -1
460			if result.Response().Response.Response != nil {
461				sc = result.page.Response().Response.Response.StatusCode
462			}
463			tracing.EndSpan(ctx, sc, err)
464		}()
465	}
466	result.page, err = client.ListByService(ctx, resourceGroupName, serviceName, filter, top, skip)
467	return
468}
469
470// Update updates an existing backend.
471// Parameters:
472// resourceGroupName - the name of the resource group.
473// serviceName - the name of the API Management service.
474// backendid - user identifier. Must be unique in the current API Management service instance.
475// parameters - update parameters.
476// ifMatch - the entity state (Etag) version of the backend to update. A value of "*" can be used for If-Match
477// to unconditionally apply the operation.
478func (client BackendsClient) Update(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendUpdateParameters, ifMatch string) (result autorest.Response, err error) {
479	if tracing.IsEnabled() {
480		ctx = tracing.StartSpan(ctx, fqdn+"/BackendsClient.Update")
481		defer func() {
482			sc := -1
483			if result.Response != nil {
484				sc = result.Response.StatusCode
485			}
486			tracing.EndSpan(ctx, sc, err)
487		}()
488	}
489	if err := validation.Validate([]validation.Validation{
490		{TargetValue: serviceName,
491			Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil},
492				{Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil},
493				{Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}},
494		{TargetValue: backendid,
495			Constraints: []validation.Constraint{{Target: "backendid", Name: validation.MaxLength, Rule: 255, Chain: nil},
496				{Target: "backendid", Name: validation.MinLength, Rule: 1, Chain: nil},
497				{Target: "backendid", Name: validation.Pattern, Rule: `^[^*#&+:<>?]+$`, Chain: nil}}}}); err != nil {
498		return result, validation.NewError("apimanagement.BackendsClient", "Update", err.Error())
499	}
500
501	req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, backendid, parameters, ifMatch)
502	if err != nil {
503		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Update", nil, "Failure preparing request")
504		return
505	}
506
507	resp, err := client.UpdateSender(req)
508	if err != nil {
509		result.Response = resp
510		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Update", resp, "Failure sending request")
511		return
512	}
513
514	result, err = client.UpdateResponder(resp)
515	if err != nil {
516		err = autorest.NewErrorWithError(err, "apimanagement.BackendsClient", "Update", resp, "Failure responding to request")
517	}
518
519	return
520}
521
522// UpdatePreparer prepares the Update request.
523func (client BackendsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, backendid string, parameters BackendUpdateParameters, ifMatch string) (*http.Request, error) {
524	pathParameters := map[string]interface{}{
525		"backendid":         autorest.Encode("path", backendid),
526		"resourceGroupName": autorest.Encode("path", resourceGroupName),
527		"serviceName":       autorest.Encode("path", serviceName),
528		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
529	}
530
531	const APIVersion = "2016-07-07"
532	queryParameters := map[string]interface{}{
533		"api-version": APIVersion,
534	}
535
536	preparer := autorest.CreatePreparer(
537		autorest.AsContentType("application/json; charset=utf-8"),
538		autorest.AsPatch(),
539		autorest.WithBaseURL(client.BaseURI),
540		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/{backendid}", pathParameters),
541		autorest.WithJSON(parameters),
542		autorest.WithQueryParameters(queryParameters),
543		autorest.WithHeader("If-Match", autorest.String(ifMatch)))
544	return preparer.Prepare((&http.Request{}).WithContext(ctx))
545}
546
547// UpdateSender sends the Update request. The method will close the
548// http.Response Body if it receives an error.
549func (client BackendsClient) UpdateSender(req *http.Request) (*http.Response, error) {
550	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
551	return autorest.SendWithSender(client, req, sd...)
552}
553
554// UpdateResponder handles the response to the Update request. The method always
555// closes the http.Response Body.
556func (client BackendsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
557	err = autorest.Respond(
558		resp,
559		client.ByInspecting(),
560		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
561		autorest.ByClosing())
562	result.Response = resp
563	return
564}
565