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