IBM Embedded Business AI Framework

Learn

Integrate

Help

API Endpoint

The api endpoint is used in cases where you wish to communicate directly to your own agent from the front end. In other words, this endpoint enables your agent to handle requests to itself from the client side. Within the endpoint, we will receive certain input params, i.e. params.input. These are the input parameters passed to the client request. The following paradigm should be employed to enable this functionality:

Below is an example that implements an ‘echo’ api request example, where @api simply returns the input data it receives.

Example:

In your frontend asset, add the following:

class MyDataRenderer extends React.Component {
  constructor(props) {
    super(props)
    this.agentInterface = new AgentInterface("sandbox", props)
  }

  handleClick() {
    this.agentInterface
      .request({ foo: "bar" })
      .then(json => console.log(json))
      .catch(xhr => console.log(xhr))
  }

  render() {
    return <a onClick={() => this.handleClick()}>test API</a>
  }
}

Within your agent’s @api endpoint, add the following:

const {Result} = require('eba')
module.exports.main = function(params) {
  return new Result(params.input)
}
edit this article