Lowdefy
v3.17.2/Connections/AxiosHttp/

AxiosHttp

The AxiosHTTP connection is used to connect to APIs and web servers using HTTP or HTTPS.

It uses the axios library.

The same properties can be set on both connections and requests. The properties will be merged, with the request properties overwriting connection properties. This allows properties like authentication headers and the baseURL to be set on the connection, with request specific properties like the request.

Secrets like authentication headers and API keys should be stored using the _secret operator.

Connections

Connection types:

  • AxiosHTTP

Requests

Request types:

  • AxiosHTTP

AxiosHTTP

Properties

  • url: string: The server URL that will be used for the request.

  • method: enum: Default: 'get' - The request method to be used when making the request. Options are:

    • 'get'
    • 'delete'
    • 'head'
    • 'options'
    • 'post'
    • 'put'
    • 'patch'
  • baseURL: string: baseURL will be prepended to url unless url is absolute. It can be convenient to set baseURL for an axios connection to pass relative URLs to requests or mutations using that connection.

  • headers: object: An object with custom headers to be sent sent with the request. The object keys should be header names, and the values should be the string header values.

  • params: object: An object with URL parameters to be sent with the request.

  • data: string | object: The data to be sent as the request body. Only applicable for request methods 'put', 'post', and 'patch'. Can be an object or a string in the format 'Country=Brasil&City=Belo Horizonte'.

  • timeout: number: Default: 0 (no timeout) - The number of milliseconds before the request times out. If the request takes longer than timeout, the request will be aborted. Set to 0 for no timeout.

  • auth: object: Indicates that HTTP Basic authorization should be used, and supplies credentials. This will set an Authorization header, overwriting any existing Authorization custom headers you have set using headers. Only HTTP Basic auth is configurable through this parameter, for Bearer tokens and such, use Authorization custom headers instead. The auth object should have the following fields:

    • username: string
    • password: string
  • responseType: enum: Default: 'json' - The type of data that the server will respond with. Options are:

    • 'document'
    • 'json'
    • 'text'
  • responseEncoding: string: Default: 'utf8' - Indicates encoding to use for decoding responses.

  • maxContentLength: number: Defines the max size of the http response content allowed in bytes.

  • maxRedirects: number: Defines the maximum number of redirects to follow. If set to 0, no redirects will be followed.

  • proxy: object: Defines the hostname and port of the proxy server. The proxy object should have the following fields:

    • host: string: Host IP address (eg. '127.0.0.1').
    • port: number: Port number.
    • auth: object: Object with username and password.

Examples

Properties for a AxiosHttp can be set on either the connection, the request, or both. However, both a connection and request need to be defined.

Using the connection to set baseURL and authorization, and handle specific requests as requests.
connections:
  - id: app_api
    type: AxiosHttp
    properties:
      baseURL: app.com/api
      auth:
        username: api_user
        password:
          _secret: API_PASSWORD
# ...
requests:
  - id: get_orders
    type: AxiosHttp
    connectionId: app_api
    properties:
      url: /orders
  - id: update_order
    type: AxiosHttp
    connectionId: app_api
    properties:
      url:
        _nunjucks: /orders/{{ order_id }}
      method: post
      body:
        _state: true
Setting properties on only the connection:
connections:
  - id: get_count
    type: AxiosHttp
    properties:
      url: myapp.com/api/count
    headers:
      X-Api-Key:
        _secret: API_KEY
# ...
requests:
  - id: get_count
    type: AxiosHttp
    connectionId: get_count
Setting properties on only the request, and using a generic connection:
connections:
  - id: axios
    type: AxiosHttp
# ...
requests:
  - id: get_api_1
    type: AxiosHttp
    connectionId: axios
    properties:
      url: app1.com/api/things
  - id: post_to_api_2
    type: AxiosHttp
    connectionId: axios
    properties:
      url: api.otherapp.org/other/thing
      method: post
      body:
        _state: true