How to use the @azure/ms-rest-js.WebResource function in @azure/ms-rest-js

To help you get started, we’ve selected a few @azure/ms-rest-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botframework-solutions / lib / typescript / botbuilder-skills / src / http / skillHttpTransport.ts View on Github external
public async forwardToSkill(
        turnContext: TurnContext,
        activity: Partial,
        tokenRequestHandler?: TokenRequestHandler
    ): Promise {
        // Serialize the activity and POST to the Skill endpoint
        const requestOptions: RequestPrepareOptions = {
            method: 'POST',
            url: this.skillManifest.endpoint,
            body: activity
        };
        const request: WebResource = new WebResource().prepare(requestOptions);

        MicrosoftAppCredentials.trustServiceUrl(this.skillManifest.endpoint);
        await this.appCredentials.signRequest(request);

        const response: HttpOperationResponse = await this.httpClient.sendRequest(request);

        if (response.status < 200 || response.status >= 300) {
            const result: string = `HTTP error when forwarding activity to the skill: Status Code:${
                response.status
            }, Message: '${
                response.bodyAsText
            }'`;

            await turnContext.sendActivity({
                type: ActivityTypes.Trace,
                text: result
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
it("Headers: Azure-AsyncOperation", async () => {
          const serviceClient: AzureServiceClient = createServiceClient([
            {
              status: 202,
              headers: new HttpHeaders({
                "azure-asyncoperation": "https://fake.azure.com/longRunningOperation2"
              })
            },
            {
              status: 200,
              body: {
                status: "Succeeded"
              }
            }
          ]);
          const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "DELETE");
          const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
          assert.strictEqual(httpResponse.status, 200);
          assert.strictEqual(httpResponse.bodyAsText, `{"status":"Succeeded"}`);
          assert.deepEqual(httpResponse.parsedBody, { status: "Succeeded" });
          assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation2");
        });
github Azure / azure-sdk-for-js / test / lroPollStrategyTests.ts View on Github external
it("with 11 AzureServiceClient.longRunningOperationRetryTimeout and 12 retry-after header", function () {
      const azureServiceClient = new AzureServiceClient(new TokenCredentials("my-fake-token"), { longRunningOperationRetryTimeout: 11 });
      const previousResponse: HttpOperationResponse = {
        request: new WebResource(),
        status: 200,
        headers: new HttpHeaders({ "retry-after": "12" })
      };
      assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 11);
    });
  });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
})
            },
            {
              status: 200,
              body: {
                status: "Succeeded"
              }
            },
            {
              status: 200,
              body: {
                a: "A"
              }
            }
          ]);
          const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "PATCH");
          const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
          assert.strictEqual(httpResponse.status, 200);
          assert.strictEqual(httpResponse.bodyAsText, `{"a":"A"}`);
          assert.deepEqual(httpResponse.parsedBody, { a: "A" });
          assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation");
        });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
})
            },
            {
              status: 200,
              body: {
                status: "Succeeded"
              }
            },
            {
              status: 200,
              body: {
                a: "A"
              }
            }
          ]);
          const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "POST");
          const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
          assert.strictEqual(httpResponse.status, 200);
          assert.strictEqual(httpResponse.bodyAsText, `{"a":"A"}`);
          assert.deepEqual(httpResponse.parsedBody, { a: "A" });
          assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation3");
        });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
it ("adds custom user agent if specified", async () => {
      const client = new AzureServiceClient(new TokenCredentials("fake-token"), { userAgent: "custom-ua" });
      const request = new WebResource("https://microsoft.com");
      await client.sendRequest(request);

      const telemetry = request.headers.get("user-agent")!;
      assert.equal(telemetry, "custom-ua");
    });
github Azure / azure-sdk-for-js / test / azureServiceClientTests.ts View on Github external
status: 200,
                headers: new HttpHeaders({
                  "location": "https://fake.azure.com/longRunningOperation2"
                })
              },
              {
                status: 202
              },
              {
                status: 200,
                body: {
                  a: "A"
                }
              }
            ]);
            const httpRequest = new WebResource("https://fake.azure.com/longRunningOperation", "PUT");
            const httpResponse: HttpOperationResponse = await serviceClient.sendLongRunningRequest(httpRequest);
            assert.strictEqual(httpResponse.status, 200);
            assert.strictEqual(httpResponse.bodyAsText, `{"a":"A"}`);
            assert.deepEqual(httpResponse.parsedBody, { a: "A" });
            assert.strictEqual(httpResponse.request.url, "https://fake.azure.com/longRunningOperation2");
          });
github Azure / ms-rest-nodeauth / lib / credentials / msiAppServiceTokenCredentials.ts View on Github external
protected prepareRequestOptions(): WebResource {
    const endpoint = this.msiEndpoint.endsWith("/") ? this.msiEndpoint : `${this.msiEndpoint}/`;
    const resource = encodeURIComponent(this.resource);
    const getUrl = `${endpoint}?resource=${resource}&api-version=${this.msiApiVersion}`;
    const reqOptions: RequestPrepareOptions = {
      url: getUrl,
      headers: {
        "secret": this.msiSecret
      },
      method: "GET"
    };

    const webResource = new WebResource();
    return webResource.prepare(reqOptions);
  }
}
github Azure / azure-sdk-for-js / sdk / storage / storage-BatchRequest.ts View on Github external
return `${this.body}${this.batchRequestEnding}${HTTP_LINE_ENDING}`;
  }

  public getMultipartContentType(): string {
    return this.multipartContentType;
  }

  public getSubRequests(): Map {
    return this.subRequests;
  }
}

class BatchRequestAssemblePolicy extends BaseRequestPolicy {
  private batchRequest: InnerBatchRequest;
  private readonly dummyResponse: HttpOperationResponse = {
    request: new WebResource(),
    status: 200,
    headers: new HttpHeaders()
  };;

  constructor(
    batchRequest: InnerBatchRequest,
    nextPolicy: RequestPolicy,
    options: RequestPolicyOptions
  ) {
    super(nextPolicy, options);

    this.batchRequest = batchRequest;
  }

  public async sendRequest(request: WebResource): Promise {
    await this.batchRequest.appendSubRequestToBody(request);