Zebra API Doc

zebra.io.HTTP Class

HTTP request class. This class provides API to generate different (GET, POST, etc) HTTP requests in sync and async modes

Constructor

zebra.io.HTTP

(
  • url
)

Parameters:

  • url String

    an URL to a HTTP resource

Item Index

Methods

Methods

GET

(
  • [q]
  • [f]
)

Perform HTTP GET request synchronously or asynchronously with the given query parameters.

Parameters:

  • [q] Object optional

    a dictionary of query parameters

  • [f] Function optional

    a callback function that is called when the HTTP GET request is done. The method gets a request object as its only argument and is called in context of the HTTP class instance.

       // synchronous HTTP GET request with the number of
       // query parameters
       var result = zebra.io.HTTP("google.com").GET({
           param1: "var1",
           param3: "var2",
           param3: "var3"
       });
    
       // asynchronouse GET requests
       zebra.io.HTTP("google.com").GET(function(request) {
           // handle HTTP GET response
           if (request.status == 200) {
               request.responseText
           }
           else {
               // handle error
               ...
           }
           ...
       });

POST

(
  • d
  • [f]
)

Perform HTTP POST request synchronously or asynchronously with the given data to be sent.

Parameters:

  • d String | Object

    a data to be sent by HTTP POST request. It can be either a parameters set or a string.

  • [f] Function optional

    a callback function that is called when HTTP POST request is done. The method gets a request as its only argument and called in context of appropriate HTTP class instance. If the argument is null the POST request will be done synchronously.

      // asynchronously send POST
      zebra.io.HTTP("google.com").POST(function(request) {
          // handle HTTP GET response
          if (request.status == 200) {
              request.responseText
          }
          else {
              // handle error
              ...
          }
      });

    Or you can pass a number of parameters to be sent synchronously by HTTP POST request:

      // send parameters synchronously by HTTP POST request
      zebra.io.HTTP("google.com").POST({
          param1: "val1",
          param2: "val3",
          param3: "val3" 
      });

SEND

(
  • method
  • url
  • data
  • [callback]
)

Universal HTTP request method that can be used to generate a HTTP request with any HTTP method to the given URL with the given data to be sent asynchronously or synchronously

Parameters:

  • method String

    an HTTP method (GET,POST,DELETE,PUT, etc)

  • url String

    an URL

  • data String

    a data to be sent to the given URL

  • [callback] Function optional

    a callback method to be defined if the HTTP request has to be sent asynchronously.