<commit_before>import { Ability, ConfigurationError, LogicError, TestCompromisedError, UsesAbilities } from '@serenity-js/core';
import axios, { AxiosError, AxiosInstance, AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios';

/**
 * @desc
 *  An {@link @serenity-js/core/lib/screenplay~Ability} that enables the {@link Actor} to call a HTTP API.
 *
 * @example <caption>Using a default Axios HTTP client</caption>
 * import { Actor } from '@serenity-js/core';
 * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 * import { Ensure, equals } from '@serenity-js/assertions';
 *
 * const actor = Actor.named('Apisit').whoCan(
 *     CallAnApi.at('https://myapp.com/api'),
 * );
 *
 * actor.attemptsTo(
 *     Send.a(GetRequest.to('/users/2')),
 *     Ensure.that(LastResponse.status(), equals(200)),
 * );
 *
 * @example <caption>Using Axios client with custom configuration</caption>
 * import { Actor } from '@serenity-js/core';
 * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 * import { Ensure, equals } from '@serenity-js/assertions';
 *
 * import axios  from 'axios';
 *
 * const axiosInstance = axios.create({
 *     timeout: 5 * 1000,
 *     headers: {
 *         'X-Custom-Api-Key': 'secret-key',
 *     },
 * });
 *
 * const actor = Actor.named('Apisit').whoCan(
 *     CallAnApi.using(axiosInstance),
 * );
 *
 * actor.attemptsTo(
 *     Send.a(GetRequest.to('/users/2')),
 *     Ensure.that(LastResponse.status(), equals(200)),
 * );
 *
 * @see https://github.com/axios/axios
 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
 *
 * @public
 * @implements {@link @serenity-js/core/lib/screenplay~Ability}
 */
export class CallAnApi implements Ability {

    /** @private */
    private lastResponse: AxiosResponse;

    /**
     * @desc
     *  Ability to Call and api at a specified baseUrl
     *
     *  Default timeout is set to 2s.
     *
     *  Default request headers:
     *  - Accept: application/json,application/xml<commit_msg>docs(rest): updated the API docs to mention my article on configuring Axios to work with proxies<commit_after>import { Ability, ConfigurationError, LogicError, TestCompromisedError, UsesAbilities } from '@serenity-js/core';
import axios, { AxiosError, AxiosInstance, AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios';

/**
 * @desc
 *  An {@link @serenity-js/core/lib/screenplay~Ability} that enables the {@link Actor} to call a HTTP API.
 *  If you need to connect via a proxy, check out [this article](https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d).
 *
 * @example <caption>Using a default Axios HTTP client</caption>
 *  import { Actor } from '@serenity-js/core';
 *  import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 *  import { Ensure, equals } from '@serenity-js/assertions';
 *
 *  const actor = Actor.named('Apisit').whoCan(
 *      CallAnApi.at('https://myapp.com/api'),
 *  );
 *
 *  actor.attemptsTo(
 *      Send.a(GetRequest.to('/users/2')),
 *      Ensure.that(LastResponse.status(), equals(200)),
 *  );
 *
 * @example <caption>Using Axios client with custom configuration</caption>
 *  import { Actor } from '@serenity-js/core';
 *  import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 *  import { Ensure, equals } from '@serenity-js/assertions';
 *
 *  import axios  from 'axios';
 *
 *  const axiosInstance = axios.create({
 *      timeout: 5 * 1000,
 *      headers: {
 *          'X-Custom-Api-Key': 'secret-key',
 *      },
 *  });
 *
 *  const actor = Actor.named('Apisit').whoCan(
 *      CallAnApi.using(axiosInstance),
 *  );
 *
 *  actor.attemptsTo(
 *      Send.a(GetRequest.to('/users/2')),
 *      Ensure.that(LastResponse.status(), equals(200)),
 *  );
 *
 * @see https://github.com/axios/axios
 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
 *
 * @public
 * @implements {@link @serenity-js/core/lib/screenplay~Ability}
 */
export class CallAnApi implements Ability {

    /** @private */
    private lastResponse: AxiosResponse;

    /**
     * @desc
     *  Ability to Call and api at a specified baseUrl
     *
     *  Default timeout is set to 2s.
     *
     *  Default request headers:
     *  - Accept: application/json,application/xml
{'fraction_non_alphanumeric': 0.15478944932901434, 'fraction_numerical': 0.008098102730217492, 'mean_word_length': 3.433846153846154, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1883203', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1454, 'n_words': 314}