Mind Expression Docs
English
  • Mind Expression Docs
  • Why Mind Expression
  • Quickstarts
    • Create Scope
    • Add Subject
    • Test
    • Audit
  • Concepts
    • Scopes
    • Subjects
    • Components
    • Sandbox
    • Conversation history
    • Webhooks and escalation
    • Knowledge
    • Live Chat
    • Target Messages
    • Analytics
  • How-to Guides
    • Set up webhooks and escalation
    • Manage global keys
    • Customize messages
    • Educate AI
      • Manage ontologies
      • Recognition Check
      • Semantic Relations
      • Manage entities
    • Steps
    • Components
      • Normal Components
        • Conditions
        • Selection Classes
        • Parameter Bundles
      • Response Components
        • Component Actions
    • Build Q&A Subjects
      • Case 1. Online Payment
      • Case 2. Data Plans
    • Build Info Search Subjects
      • Case 1. Data Usage
      • Case 2. Payment History
    • Build Query Freestyle Subjects
      • Case 1. Data Purchase
      • Case 2. Change Mobile Plan
    • Intelligent Process
      • Introduction to Mindscript
      • Mindscript with Mind Expression
      • Frequently Asked Question
      • Package: Collections and Sequenceable
      • Package: Collections Unordered
      • Package: Collections-Strings
      • Package: Engine-Conversation
      • Package: Kernel-HTTP
      • Package: Kernel-Methods
      • Package: Kernel-Numbers
      • Package: Kernel-Dates
      • Package: Kernel-Objects
      • Package: Kernel Exceptions
      • Package: Cryptography
    • Test and debug
    • Integration
      • Mind Expression API
      • Chat Widget
      • LINE
      • Facebook Messenger
      • Viber
      • Instagram
      • Discord
      • WhatsApp
      • Google Sheet
        • Google Sheet Webhook
      • Google Calendar
        • Google Calendar Webhook
        • Google Calendar: Use Cases
    • Audit AI Activities
    • Live Chat
    • Target Messages
    • Back up, import and restore Scopes
  • Reference
    • Glossary
    • API Docs
Powered by GitBook
On this page
  • Class: HTTPClient
  • Introduction
  • Instance Method
  • Class: UUIDGenerator
  • Introduction
  • Class Method

Was this helpful?

  1. How-to Guides
  2. Intelligent Process

Package: Kernel-HTTP

Class: HTTPClient

Introduction

Environment: container

HTTPClient is a HTTP client library.

It has the following attributes:

  • host the host of the request

  • port the port of the request

  • url the url of the request

  • timeout the timeout of the request

  • contents the contents of the request

  • contentType the content type of the request

  • method the http request method.

It has the following methods:

  • queryAt:put: Add key equals value as an HTTP query parameter to the current request.

  • headerAt:put: Add key equals value as an HTTP header to the current request.

  • execute execute the request

  • get execute a get request

  • put execute a put request

  • post execute a post request

  • delete execute a delete request

  • head execute a head request

You can use it to make HTTP requests to a server.

for example, for a HTTP get:

httpClient := HTTPClient new.
httpClient url: 'http://www.example.com'.
result := httpClient get.

and for a HTTP post:

httpClient := HTTPClient new.
httpClient url: 'http://www.example.com/api'.
httpClient
 contents:
 { ('key1' -> 'key1').
   ('key2' -> 2) } asJson.
result := httpClient post.

The result is a Dictionary which has three keys:

  • status The http status code.

  • headers The http headers.

  • response The http response body. It wil be parsed as JSON if possible, otherwise it will be a string.

For example, you can check the status code like this:

result := httpClient get.
" If the HTTP status code differs from 200, exit the current block. "
(result at: 'status') = 200 ifFalse: [ ^ nil ].

Sometimes, the http request may raise an error for a failure request, we can catch error like this:

error := nil.
[ httpClient get ] onErrorDo: [ :ex | error := ex ].
" If error is not nil, it means the http request failed. "
error ifNotNil: [
  " The error is an APIError object, we can check the error code like this: "
  error code = 'http-request-error'.
  "we can terminate the execution by caret operator.  "
  ^ nil ].

Instance Method

Category: accessing - request

  • contentType - Get the contentType of the HTTPClient.

  • contentType: - Set the contentType of the HTTPClient.

  • contents - Get the contents of the HTTPClient.

  • contents: - Set the contents of the HTTPClient.

  • headerAt:put: - Set key equals value in the HTTP header of the current request.

    For example:

    self headerAt: 'x-conversation-id' put: UUIDGenerator next.
  • host - Get the host of the HTTPClient.

  • host: - Set the host of the HTTPClient.

  • method - Get the method of the HTTPClient.

  • method: - Set the method of the HTTPClient.

  • port - Get the port of the HTTPClient.

  • port: - Set the port of the HTTPClient.

  • queryAt:put: - Add key equals value as an HTTP query parameter to the current request.

    If a key is already present, its corresponding value will be replaced.

    For example:

    self queryAt: 'id' put: '12'.
  • timeout - Get the timeout of the HTTPClient.

  • timeout: - Set the timeout of the HTTPClient.

  • url - Get the url of the HTTPClient.

  • url: - Set the url of the HTTPClient.

Category: operations

  • delete - Execute an HTTP DELETE the request set up and return the response #contents.

  • execute - Execute the currently set up request to generate a response. Return the #contents of the response, if any.

  • get - Execute an HTTP GET the request set up and return the response #contents.

  • head - Execute a HTTP HEAD on the request set up and return nil.

  • post - Execute an HTTP POST the request set up and return the response #contents.

  • put - Execute an HTTP PUT the request set up and return the response #contents.

Class: UUIDGenerator

Introduction

Environment: container

The UUIDGenerator generates UUIDs, this can be used by following the syntax below

"Return a new UUID string."
UUIDGenerator next

Class Method

Category: accessing

  • next - returns a new UUID string.

PreviousPackage: Engine-ConversationNextPackage: Kernel-Methods

Last updated 1 year ago

Was this helpful?