Back to Lowdefy

@lowdefy/connection-axios-http

code-docs/plugins/connections/axios-http.md

5.2.03.9 KB
Original Source

@lowdefy/connection-axios-http

HTTP/REST API connection for Lowdefy using Axios.

Connection Type

TypePurpose
AxiosHttpConnect to HTTP/REST APIs

Connection Configuration

yaml
connections:
  - id: api
    type: AxiosHttp
    properties:
      baseUrl: https://api.example.com
      headers:
        Authorization:
          _string:
            - 'Bearer '
            - _secret: API_TOKEN

Properties

PropertyTypeDescription
baseUrlstringBase URL for requests
headersobjectDefault headers
timeoutnumberRequest timeout (ms)
authobjectBasic auth credentials

Request Type

TypePurpose
AxiosHttpMake HTTP request

Request Configuration

yaml
requests:
  - id: getUsers
    type: AxiosHttp
    connectionId: api
    properties:
      url: /users
      method: GET
      params:
        page:
          _state: page
        limit: 20

Request Properties

PropertyTypeDescription
urlstringRequest URL (appended to baseUrl)
methodstringHTTP method (GET, POST, PUT, DELETE, PATCH)
paramsobjectURL query parameters
dataanyRequest body
headersobjectRequest-specific headers
timeoutnumberOverride connection timeout
responseTypestringExpected response type

Examples

GET Request

yaml
requests:
  - id: fetchData
    type: AxiosHttp
    connectionId: api
    properties:
      url: /items
      method: GET
      params:
        search:
          _state: searchQuery

POST Request

yaml
requests:
  - id: createItem
    type: AxiosHttp
    connectionId: api
    properties:
      url: /items
      method: POST
      data:
        name:
          _state: name
        description:
          _state: description

PUT Request

yaml
requests:
  - id: updateItem
    type: AxiosHttp
    connectionId: api
    properties:
      url:
        _string:
          - '/items/'
          - _state: itemId
      method: PUT
      data:
        _state: formData

DELETE Request

yaml
requests:
  - id: deleteItem
    type: AxiosHttp
    connectionId: api
    properties:
      url:
        _string:
          - '/items/'
          - _state: itemId
      method: DELETE

File Upload

yaml
requests:
  - id: uploadFile
    type: AxiosHttp
    connectionId: api
    properties:
      url: /upload
      method: POST
      headers:
        Content-Type: multipart/form-data
      data:
        file:
          _state: fileInput

Custom Headers

yaml
requests:
  - id: authenticatedRequest
    type: AxiosHttp
    connectionId: api
    properties:
      url: /protected
      method: GET
      headers:
        X-Custom-Header: value
        Authorization:
          _string:
            - 'Bearer '
            - _user: accessToken

Response Handling

The response includes:

  • data - Response body
  • status - HTTP status code
  • headers - Response headers

Access in state:

yaml
_request: getUsers.data

Error Handling

HTTP errors throw RequestError with:

  • Status code
  • Response data
  • Original error message

Handle in actions:

yaml
events:
  onClick:
    - id: fetch
      type: Request
      params:
        requestId: getUsers
      onError:
        - id: showError
          type: Message
          params:
            content: Request failed
            type: error