HTTP

Overview

HTTP is a Dyalog cover class for Asynchronous HTTP request using the .Net HttpClient.

Typical Usage

Instantiating the class

      http ← ⎕NEW HTTP

GET Request

The method GET sends a GET request to the specified Uri and returns the response as Bytes (numbers 0-255) in an asynchronous operation. The response can be transform to characters by using ⎕UCS with the proper encoding.

      r ← {timeOut}http.GET(url get)

    ⍝ url = IP Address as numbers (192 168 1 1) or characters ('192.168.1.1' or 'www.mysite.com')
    ⍝ get = GET request
    ⍝ timeOut = Optional delay to wait for the completion of the GET request in milliseconds
    ⍝           If not specify, the value of the Field _TimeOut will be used (default is 5 seconds)

    ⍝ r[1] = 1 for Success, 0 for Failure
    ⍝ r[2] = Response as bytes if Successful, Literal Error if Failure

Here is some examples:

      http ← ⎕NEW HTTP


      request ← http.GET 'www.rfc-editor.org' '/rfc/rfc793.txt'

      1↑request                                  ⍝ Check that request was successful
1
      request ← ⎕UCS 2⊃request                   ⍝ Convert bytes to characters with no encoding
      request ← ⊃{⎕ML←3 ⋄ (⍵≠⎕UCS 10)⊂⍵}request  ⍝ Format the request as text
      )ED request


      request ← http.GET 'www.google.com' '/search?q=dyalog+apl'

      1↑request  ⍝ Check that request was successful
1
      request ← 'UTF-8' ⎕UCS 2⊃request           ⍝ Convert bytes to characters with UTF-8 encoding
      request ← 1↓,(⎕UCS 13),'<',⊃{⎕ML←3 ⋄ (⍵≠'<')⊂⍵}request  ⍝ Format the request as HTML
      )ED request


      request ← http.GET 'www.dyalog.com' ''     ⍝ Empty GET request returns the URI

      1↑request                                  ⍝ Check that request was successful
1
      request ← 'UTF-8' ⎕UCS 2⊃request           ⍝ Convert bytes to characters with UTF-8 encoding
      )ED request

How to install HTTP in your workspace

  1. Download HTTP.v1.0.txt

  2. Do a Select all (Ctrl+A) and a copy (Ctrl+C).
  3. In your workspace execute )ed ○ HTTP

  4. Paste (Ctrl+V) the text into the Dyalog editor
  5. Press Escape and ')save' your workspace

Version Information

 Version 1.0 January 2016, Pierre Gilbert

Original author:

Pierre Gilbert

Responsible:

PierreGilbert

Email:

<apgil AT SPAMFREE videotron DOT ca>


See also: netTCP netUDP


CategoryDyalog - CategoryDyalogDotNet - CategoryDotNet

netHTTP (last edited 2016-01-11 12:31:47 by PierreGilbert)